这场codeforces打的非常惨,B题被HACK成功了两次,终于明白为什么比赛时通过了叫pratest passed而不是Accepeted,B题我思路还不对时就能通过两次,说明codeforces是故意留给HACK空间的,然后B题D题都是非常不错的题目,B题关于二进制位运算,D题是概率题,
题意:合成一个yellow球需要2个yellow元素,合成一个green球需要1个yellow元素加1个blud元素,合成一个blue球需要3个blue元素,现有A个yellow元素,B个blude元素,想要得到A,B,C个yellow,grean,blue球,问每种元素还需要多少
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
这里当k=1即只能选一个数时输出n即为最大
k>=2时,n化为二进制后每一位都换为1的值即为结果,比如n=8,K=2;
那么8化为二进制8->1000,我们只需在1~8中选7,7化为二进制7->0111,则(1111)XOR(0111)=1111,答案即为(2^5)-1
其实这里当k>=2时,我们也只需要选一个数,即能与n异或时互补的那个数,
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 105, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 105)).
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10 - 9. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if .
3 3 2 3
2.0000000000
12 17 9 40
32.8333333333
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value.
题意:有一个n*m的方格(鱼塘),有一个r*r的渔网,我们要往鱼塘中放k条鱼,一小方块只能放一条鱼,有某种放鱼的方法使得一网捞到的鱼的数量的期望值最大,求次期望值
题目可以一条一条鱼的往池塘里放,每次都放到当前可以被最多的r*r矩形覆盖的点上,并记录该点被r*r矩形的覆盖的个数val,放进优先队列。
这里关键是我们从可以被最多的r*r矩阵覆盖的点开始放鱼(也就是可以最大概率有鱼的点),然后搜索此点周围的点。
这里先放进优先队列的点并不是我们要选择的点,而是选择队列中val最大的点
其实此做法可以转化为公式(p1/p2),p2是所有放网的情况,p1是所有情况下可以捞到的鱼的数量之和(最优方案下)
参考:http://codeforces.com/contest/912/submission/33958896
http://www.cnblogs.com/FxxL/p/8207466.html
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include