error202's blog

By error202, 11 years ago, In English

A

brute force max(x,y)/min(x,y) then just do it

B

because of t only 50000,the length of side of final board wont be very large make a table then you can find the length of side <=60.So brute force

C

every time choose two vector u v that d[u]=A[u]-B[u]>0 && d[v]=A[v]-B[v]<0 find a flow from u to v.obviously after that at least one d of u v will be 0 (d[u]==0||d[v]==0) also one work will use no more than n edges one work at least fit one vector's meet,there are n vector,So the total number is less than n*n

D define base number is the number can not be other number's power(like 2 3 6 but not 4 16) define base set is the set of one base number's power obviously,every base set is independent so we only care about the SG of every set (NIM game) then we consider two sets’ total number of elements are same (card(A)=card(b))
if we y is x's power we build a edge between x y then we can find if two set's size is same then the edge are also same maximum is log(10^9)<30 so question is to find SG(0) SG(1)... SG(29) how to calculate SG(x)? x<=30 brute force! last calculate all base set's size and xor

E very interesting! first if m==0 of course -1 if m==1 easy to find a way m>1 case 1: there is not a path connected s t

It mean somes tree surround s or some trees surround t
  So you can not put s t into same cell

case 2: there is a path connected s t in this case solution will always exist our strategy is princess follow the shortest path shortest path gives princess a queue of the steps that she should perform. Addition if shadow moves, then we add her move to the queue. In our strategy firstly we can find the distance between princess and her shadow will no-increase.

case 2.1

       if in a time the distance between princess and her shadow decrease to 0 then             that's the way
  case 2.1 
        if the distance awalys >0
        in this case we consider the left-most tree as tl and right-most tree tr.
        if the distance still >0 after a long time we can imagine that princess and her shadow will go far away from all the tree. 
        draw a small graph(X-axis)
        there are only four possibilities 
        (1)princess-shadow-tree

        (2)shadow-princess-tree 

        (3)tree-princess-shadow

        (4)tree-shadow-princess

        (2)(3) transform to (4)(1) by using operator[UUUUUU...LLLLLLL...(orRRRRRR...)DDDDDDDD....]

        in possibility (1) we can use tree tl to catch shadow  

        in possibility (2) we can use tree tr to catch shadow(this two just like m==1)

so whole problem be solved

Full text and comments »

  • Vote: I like it
  • +15
  • Vote: I do not like it

By error202, 11 years ago, In English

It's a bracket match problem and all given bracket is left bracket using dp f[i][j] first i character match j pair of bracket

if s[i]=='?' then it can match a new pair so f[i][k]=f[i-1][k]+f[i-1][k-1] (0=<k<=i/2 && if s[i]=='?') else f[i][j]=f[i-1][j] (0<=j<=i/2)

at last remember multiply 25 if '?' match '?'

though it it n^2 but it really fast data that is 100000 '?' using around 4 second so it can pass the testdata

(but I feel it can be optimized because this dp's transfer is very special maybe lazy lag or something else)

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By error202, 11 years ago, In English

For the CET-6!

A: a easy problem n*(n-1)/4*(2*t/l) for the whole circle the left time change the circle to a line and double the length then binary search or two pointer scan as you like

B: record each word's length then calculate if the this word is the last word of a line then which one if the first word of this line. then calculate if this word is the last word of ad then which one is the first word of this ad. all this can use two pointer work in o(n). but a litter bit complex.(and i am too lazy to write code)

C: account the how mant exist and needed length 2^j. then greed, obviously if we can meet the request for 2^i 2^j (i<j) then we will work for 2^i first.also if there are 2^i 2^j are empty and 2^k request (k<i<j) then we will take the 2^i

D: middle school geometry problem can somebody tell me how to put picture in blog? (it is hard to explain without picture)

E: First binary the answer is obvious then the question is how to check the answer Also it is greedy the greedy strategy put the sheep i that can be in put and ri is minimum to put more sheep in, so after put in the line the number of expand sheep should be as small as possible let i is available and ri is minimum a1 a2 a2..at is intersect with i so for each ai, ai aj is intersect if we don't put i in the line but any ap and the expand number will at least t.it can't be more optimized.

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By error202, 12 years ago, In English

题目最难点就是前面的区间离散 如果能想到这个这道题就不难了 把所有的l[i] r[i] 放在一起然后排序 考虑一个区间 先把所有可能取到这个区间的点取出来 计算出这些点在这个区间内 区间左 区间右的概率 记为 pl pm pr 那么一个点在这个区间内 他排名的的概率可以这么计算 f[i][x][y] 前i个i点 在这个区间内有x个点 区间前面有y个点 转移就是第i个点加进来 考虑是在左边 中间 还是右边 f[i][j][k]+=f[i-1][j-1][k]*pl[i]; f[i][j][k]+=f[i-1][j][k-1]*pm[i]; f[i][j][k]+=f[i-1][j][k]*pr[i]; 注意到如果在同一个区间内有k个人 那么期中任意一个人排1-k名的概率是一样的 所以可以这么 统计答案: for (int x=0;x<m;x++) for (int y=0;y<m-x;y++) for (int k=0;k<=y;k++) rec[id[p]][cnt+x+k+1]+=pm[p]*f[m-1][x][y]/(y+1);

直接裸做DP的话 效率是 n^5 好像是堪堪过 可以看到在同一个区间里面计算不同点的 f[i][x][y] 时 他们之间有很大一部分的dp过程是一模一样的 所以肯定还是可以优化的 (一开始我想的是 f[i][x][y]表示从1到i的 t[i][x][y] 表示i到m的 然后计算的时候从f[i-1] t[i+1]得到答案 但是算了算 是N^6 比暴力还差。。。囧,这样二元的多项式函数乘积如果可以FFT也许也行,不过二元FFT 想想也就呵呵了) 后来看到了CLJ的代码 他是分治搞的 ORZ 代码也容易理解 这里就不说了 分治的话 就是N^4logN

懒得敲分治了 直接就写暴力了

Full text and comments »

  • Vote: I like it
  • -33
  • Vote: I do not like it

By error202, 12 years ago, In English

又是一道神DP 还是太弱了 不会搞 PR给了一个100*100*50*50*100的算法 后来看别人的100*50^4没看懂 最后Fu点醒了我

先说的PR的方法 . . . . . . . . . . . 显然good array 必然是类似山峰状的一个东西 可以像搭房子一样从下到上一层一层的往上搭 ? ? . . . . . . . 将{bi}看做一个数字序列,比如将222223333445555666看做5,4,2,4,3(相同数的个数),记作{ci} ans=1 A=c1 for(i=2;i<=|ci|;i++) { B=ci; ans*=C(B-1,A-1); //如果A==0或A>B这条式子本身就不成立,式子中已经包含了无解的条件 A=B-A; } f[i][j][k][s] 表示现在这一层的数是i(你可能从2,3,4...开始"建房子",地基的位置是由{bi}中的最小值决定的), 已经用掉(包括当前最小点)j个点, 总方案数为k, 当前这一层有s(就是上面伪代码中的A)段的方案数 -> (枚举第i+1层要放l个点(即上面伪代码中的B)) f[i+1][j+l][k*C(l-1,s-1)][l-s] (l > s)

显然 i l 是<=n/2 k j<=n 转移是 N 所以是 100^3*50^2 // 题解的方法更加神

题解的大致思路和上面相同 但是在设计状态的时候却更加巧妙 f[i][count][lastnumber][way] 用了前i个数 一共有 count个数 上一个数用了lastnumber次 有k种方法弄good way

注意巧妙的用了 上一个数用了lastnumber次 那么在这次转移中 如果我们要加入y个i+1但是 一个i+1 的周围肯定是两个i所以要再加一个i+1 必须要加一个i 来套住他 由于原来的i不会有相邻的所以这样总是可行的方案。 然后算新的方案: 就是对于原来的每个i,我可以添加 ai个i+1 那就是 a1+a2+..+ax=y 非负整数解的个数就是 C(x+y-1,x-1)=C(x+y-1,y) (隔板法) f[i][count+2*y][y][nowway]+=f[i][count][lastnumber][way] 又由于每次count加的都是2的倍数 所以第二维 和转移也都变成了 n/2 所以是 100*50^4

Full text and comments »

  • Vote: I like it
  • -23
  • Vote: I do not like it

By error202, 12 years ago, In English

几何题一直不会搞 后来看懂了题解 自己懒得写了 直接交了别人的代码 显然让求的是 2*sigma{(xi-xj)^2+(yi-yj)^2} 所以把x和y 独立出来分别计算(自己想的时候莫名奇妙的给他加了一个根号去想两点之间的距离了。。然后死也想不出来了 我真是不能再2了) 现在考虑 sigma(xi-xj)^2 记sum为所有可能的点的个数 x的范围是 10^6 所以可以处理每一个x上有多少个点 记为F(x) 那么答案就是 sigma(x-y)^2*Fx*Fy=sigma((x^2+y^2-2xy)*Fx*Fy) (Fx的统计是先找到xmin 和 xmax 用一个指针扫一遍) 再考虑 sigma(x^2FxFy)= sigma(x^2Fx*sigma(Fy))=sum*sigma(x^2*Fx) 同理 sigma(y^2FyFx) 也是 sum*sigma(x^2*Fx) 然后 是 2xyFxFy 这东西因式分解一下变成了 sigma(x*Fx)*sigma(y*Fy)=sigma(x*Fx)^2 x^2Fx xFx sum 都是 o(n) 可以统计出来的 然后 算个总和 除掉 (sum)*(sum-1)/2 再然后 就没有然后了

Full text and comments »

  • Vote: I like it
  • -29
  • Vote: I do not like it

By error202, 12 years ago, In English

令 f[i][j] 表示 i层的树进行了j步的方案数 转移是这样的 看根节点 我们要把j的步去掉根本身的一步后 剩下的j-1步分配给自己的儿子 从而可以去掉根节点 成为了一个 变成4个 i-1层 k步的子问题。 合并的时候用类似背包的思想 从第一个儿子哪里拿k1 个 第二个k2个 第三个 k3个。。。 01背包维护 即可

FFT 做法: 在f[i][j] 中可以看到 令p_i(x)=sigma {f[i][j]*x^j} 即 f[i]的母函数 那么上述的转移可以看成 p_(i+1)(x)=x*[p_i(x)]^4+1 后k项的系数就是 f[i+1][k] 用FFT计算[p_i(x)]^4 可以把转移优化到 klogk

Full text and comments »

  • Vote: I like it
  • -18
  • Vote: I do not like it

By error202, 12 years ago, In English

F[i][j][a][b] 表示前i个数有j个good position 并且在第i位置和第i+1位置的状态是a和b (0表示不是good position 1表示是 good position)而不管其他数如何放置的方案数 于是有转移f[i][j][a][b]->f[i+1][j][b][0] i+1放在前面 f[i][j][0][b]->f[i+1][j+1][b][0] i+1 放在i位置 f[i][j][a][b]->f[i+1][j+1][b][1] i+2 放在i+2位置

最后统计得到 p[i]=sigma f[n][i] 但是注意到这里p[i]满足了有i个good position 的方案数 然后我们需要考虑剩下的n-i个数 让 p[i]*(n-i)! 得到了k 个good position和剩下数的全排列的方案数,但是注意到全排列之后会有更多的 good position.有k个good position的排列会出现C(k,i)次(k>=i) 由于之前的p[k]已经得出 所以减掉 p[k]*C(k,i)就是答案

Full text and comments »

  • Vote: I like it
  • -20
  • Vote: I do not like it