0%

题目描述:

RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner。考虑到经费问题,boss刘决定只让找到partner的人去坐过山车,其他的人,嘿嘿,就站在下面看着吧。聪明的Acmer,你可以帮忙算算最多有多少对组合可以坐上过山车吗?

Read more »

题目描述:

C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。 中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算这一段的总人数并汇报。但敌兵营地的人数经常变动,而Derek每次询问的段都不一样,所以Tidy不得不每次都一个一个营地的去数,很快就精疲力尽了,Derek对Tidy的计算速度越来越不满:“你个死肥仔,算得这么慢,我炒你鱿鱼!”Tidy想:“你自己来算算看,这可真是一项累人的工作!我恨不得你炒我鱿鱼呢!”无奈之下,Tidy只好打电话向计算机专家Windbreaker求救,Windbreaker说:“死肥仔,叫你平时做多点acm题和看多点算法书,现在尝到苦果了吧!”Tidy说:“我知错了。。。”但Windbreaker已经挂掉电话了。Tidy很苦恼,这么算他真的会崩溃的,聪明的读者,你能写个程序帮他完成这项工作吗?不过如果你的程序效率不够高的话,Tidy还是会受到Derek的责骂的.

Read more »

树上的分治分两种:点分治边分治,点分治由于其比较稳定的复杂度,是两者中更为常用的一种。

点分治

顾名思义,就是将树用重心分割为几块,然后在每棵树中进行类似“暴力”的操作,已达到复杂度优化的作用 重心,即一棵树上的一个点,以其作为根,其最大子树大小最小的点

复杂度

考虑最坏情况,一个重心只有两个子树,那么当你如此分割时,两颗子树的大小都大概是原树大小的一半左右,若在每棵树中的操作都是O(n)的话,最后复杂度便为O(nlogn),然而这是最坏情况,若平均起来,会比它还小一些,可见它是十分有效的。

Read more »

题目描述:

Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid if and only if dist(u,v) not exceed k. Write a program that will count how many pairs which are valid for a given tree.

Read more »

题目描述:

Lady CA has a tree with n points numbered 1,2,…,n, and each edge has its weight. The unique route connecting two points is called a chain, and the length of a chain equals the sum value of the weights of the edges passed.

The point number m is called the root. Lady CA defines a special kind of chain called folded chain, the chain connecting the points numbered x,y(x≠y) is called a folded chain, if and only if the chain connecting the point numbered x and the root doesn’t pass the point numbered y, and the chain connecting the point numbered y and the root doesn’t pass the point numbered x.

Lady CA wants to find the length of the kth longest folded chain. Notice that the chain connecting the points numbered x,y and the chain connecting the points numbered y,x are the same.

Read more »

题目描述:

给你一个数列,\(k\)\(maxDist\),要你从数列中选出k个数,按照原来的先后顺序排成一个新的数列,要求:新的数列中的每对相邻的数在原数列中的距离不超过\(maxDist\)。求满足条件的数列中,k个元素乘积的最大值。

Read more »

题目描述:

一个理想字符串的定义是每个字符第一个出现的位置编号就是等于这个字符出现的次数,比如 ABOOOB就是一个理想字符串(A第一次出现的位置是1,一共有一个1O最早出现的位置是3,一共有三个O,B第一次出现的位置为2,一共有2B)。给定长度length,返回字典序最小的理想字符串,如果没有,则返回空串

Read more »

题目描述:

令函数f(x)(x为正整数),返回值为x位数中的最长连续相同的数字长度,比如f(344488)=3,f(123)=1. 现在给你两个正整数nk, 要求计算出有多少个位数不大于n的数x满足f(x)=k. 返回的答案向44444444取模

Read more »

题目描述:

Given a circle sequence A[1],A[2],A[3]……A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1]. Now your job is to calculate the max sum of a Max-K-sub-sequence. Max-K-sub-sequence means a continuous non-empty sub-sequence which length not exceed K. 给定一个环,A[1],A[2],A[3],…A[n],其中A[1]的左边是A[n]. 求一个最大的连续和,长度不超过K。

Read more »