Description Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain,…
题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一条边之后,树的直径长度要么不变,要么会增加1,并且如果树的直径长度增加1了,新的直径的端点其中一个必然是新增的点,而另一个是原来直径的某个端点.关于为什么可以这样做,在Quora上有个回答解释地不错,可以参考. 实现 所以这个问题其实就是要计算树上任意两个点的距离,LCA可以很轻松地处理. 可以一次…
Description Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree w…
Description The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.…
Description Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of n brains and m brain connectors joining some pairs of brains together. It was obser…
Description "The zombies are lurking outside. Waiting. Moaning. And when they come..." "When they come?" "I hope the Wall is high enough." Zombie attacks have hit the Wall, our line of defense in the North. Its protection is…
Description One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the rea…
http://codeforces.com/contest/1184 A1 找一对整数,使x^x+2xy+x+1=r 变换成一个分式,保证整除 #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<vector…
G. Fake News (easy) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look sil…
Description The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integersa1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement.…
Description Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borr…
来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包,最多装k本书,你在第i天需要拥有一本编号ai的书,但是你可以去商店购买并加入背包. 问你至少要买多少本书?n,k<=400000 显然可以贪心,留下下一次需要的时间最早的书就行了. #include<iostream> #include<cstdio> #include<…
第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: loser大佬切了A,G: 然后翔哥在攻H题: N题好像是费用流,(看了一会才发现的我果断被同在机房打比赛的别的队的大佬D了233) 然后写出了之后,那个大佬说费用流T了,交都没交就弃掉了: (事后才知道大概是图建的不好) loser大佬B题写的差不多了,交上去WA... 翔哥在攻H题: 我开始看K题…
Description Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver state…
题意:n个数字1-m,问取k个组成的set方案数 题解:假设某个数出现k次,那么生成函数为\(1+x+...+x^k\),那么假设第i个数出现ai次,结果就是\(\sum_{i=1}^m(1+x+...+x^{a_i})\),第k项即为答案,启发式合并fft即可 组合(即set):普通生成函数.排列:指数型生成函数 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) //#pragma GCC…
Helvetic Coding Contest 2019 A2 题意:给一个长度为 n 的01序列 y.认为 k 合法当且仅当存在一个长度为 n 的01序列 x,使得 x 异或 x 循环右移 k 位的 01 串得到 y .问合法的 k 的个数. \(n \le 2*10^5\) key:找规律 考虑如何check一个 k 是否合法.那么对于所有的 i 和 i-k 在模 n 的意义下,如果 y 的第 i 位为 0 则二者必须不同,否则必须相同.这样可以用并查集判断是否合法.实际上是把相同的缩起来后…
题目链接:戳我 小注:其中部分(大括号不换行的)代码是BLUESKY007神仙写的. 咕 CF1184 A1 直接枚举,以根号的时间复杂度判断即可.注意x,y都是正整数. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define MAXN 100010 #define ll long long using na…
题意:每个点i有\(s_i\)个人和\(b_i\)份食物,每个人都要找到一份食物.现在有M条有向边,从点i到点j,容量为c,第一次走过不要紧,从第二次开始就要承担\(p(0<p<1)\)的道路损坏的风险.题目保证每个人都能拿到食物,求这个风险的最小值. 分析:建立源点S和汇点T.从S到点i建容量为\(s_i\),费用为0的边;从点i到T建容量为\(b_i\),费用为0的边. 风险的最小值可以转化为求安全达成目标的. 则\(ans = \prod (1-p_i)^{k_i}\), 对ans取对数…
Description 传送门(翻译就别想了,本人英语太垃圾) Solution 设ans[i]为设置i个船时能控制的最多星球数(看到这你可能因为是dp,然而我可以很负责地告诉你是假的) 首先一个显然的结论,ans[1]=1,ans[2]=树的直径长 有由B1题的提示我们也可以得到一个显然的结论,要使控制数最多,其实只有叶子节点是有用的 如果这样,那就比较容易了. 我们可以先找出树的直径,然后从直径上的点向外扩展,记录每个节点的深度(叶子节点深度为一个常数,反正只要一样又不会爆类型就无所谓) 为…
Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 5968    Accepted Submission(s): 1413 Problem Description A coding contest will be held in this university, in a huge playground. Th…
题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks,…
Problem DescriptionA coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the ui-th block to the v…
题目链接:https://www.nowcoder.com/acm/contest/207/G 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 时间限制:C/C++ 2秒,其他语言4秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述 A coding contest will be held in this university, in a huge playground. Th…
Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1751    Accepted Submission(s): 374 Problem Description A coding contest will be held in this university, in a huge playground. The…
Coding Contest http://acm.hdu.edu.cn/showproblem.php?pid=5988 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 5337    Accepted Submission(s): 1256 Problem Description A coding contest will be he…
Problem Description A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the u_i-th block to the…
很巧妙的建边方式 题意:有n个区域,每个区域有一些人数si和食物bi,区域之间有m条定向路径,每条路径有人数通过上限ci.路径之间铺了电线,每当有人通过路径时有pi的概率会触碰到电线,但是第一个通过的人一定不会触碰到电线.求每个人都通过路径获取到食物后触碰到电线的最小概率. 解法:不碰到电线的概率比较好求,然后对于一条路线上的不碰到电线的概率是(1-p1)*(1-p2)...,最小费用流是没法跑乘法的,所以我们建边的费用变成log(1-p),那么乘法就变成了加法,然后要求最小值,由于log(1-…
C. Without Text 题目连接: http://www.codeforces.com/contest/656/problem/C Description You can preview the image in better quality by the link: http://assets.codeforces.com/files/656/without-text.png Input The only line of the input is a string (between 1…
Problem D Lost in Translation The word is out that you’ve just finished writing a book entitled How to Ensure Victory at a Programming Contest and requests are flying in. Not surprisingly, many of these requests are from foreign countries, and while…
2016青岛现场赛的一题,由于第一次走过不会产生影响,需要拆点,不过比赛时没想到,此外还有许多细节要注意,如要加eps,时间卡得较紧要注意细节优化等 #include <iostream> #include <cstring> #include <queue> #include <cstdio> #include <cmath> #include <cstdlib> #include <algorithm> #includ…