10 2012 档案
摘要:判断图是否连通,连通的话如果每个点的度为偶数就存在欧拉回路,否则就不存在。/* * hdu1878/win.cpp * Created on: 2012-9-7 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <s
阅读全文
摘要:这题两年前就看到了,据说就一个公式而已,可是我不会推,所以一直放到现在。可是今天推来推去,还是推不出那个公式,所以最后还是用DP做了。我能推出来的部分很简单,就是指数型母函数,f(x) = (1 + x^2/2! + x^4/4! + ... )^2 * ( 1 + x + x^2/2! + x^3/3! +... )^2,公式就是x^n项的系数了,可是这个我不会,求路过的大牛指点……
阅读全文
摘要:挺简单。假设我们现在面对两个要排的队a1, b1和a2, b2,已经花的时间为t,则先排1队需要的时间是a1+a2+t+tb1+tb2+tb1b2+a1b2,而先排2队需要时间是a1+a2+t+tb2+tb1+tb1b2+a2b1,所以实际上只要比较a1b2和a2b1的大小就能确定先排哪个队。按此排个序就行了。/* * hdu4442/win.cpp * Created on: 2012-10-30 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include &
阅读全文
摘要:比较简单的模拟题,可是我刚开始读题理解有问题,Tom will change his direction into Jerry's direction, and Jerry also will change his direction into Tom's original direction这句话,我想多了,以为交换的时候,Jerry得换成Tom最开始的运动方向。改了这个就过了,1Y。/* * hdu4452/win.cpp * Created on: 2012-10-29 * Author : ben */#include <cstdio>#include &l
阅读全文
摘要:挺水的题。我的做法是用ans = N*M*K减去不和谐的数目。首先,对每一个paints shoes对,ans -= N,这是没有问题的。这个操作全执行完以后就能记录每个paints跟多少shoes和谐(用paintspair[i]表示)。然后对于每一个clothes paints对,ans -= paintspair[i],这样就避免了重复计数。/* * hdu4451/win.cpp * Created on: 2012-10-29 * Author : ben */#include <cstdio>#include <cstdlib>#include <cs
阅读全文
摘要:其实这题算动态规划有点牵强,因为它最大的难点和突破点在于把问题进行转化。我的做法是,先数出字符串的总数total和'A'的数目anum,然后只要在字符串中找出长度为anum的连续一段,它的'A'数最多就行了(假设是maxnum,则最后结果就是anum-maxnum)。找这个包含最多'A'的段才用到动态规划,其实挺简单的,就是循环一次记录从每个点起始往右长度为anum的段中'a'的数目即可。/* * hdu3819/win.cpp * Created on: 2012-10-29 * Author : ben */#include
阅读全文
摘要:刚开始看到这题的时候,理解错了数据范围,以为K<100,那就是道高精度水题了,于是用java打了交,runtime error!然后就想出了这么个模拟的方法,直接用一个数组存下fibonacci表示的数,两个数合并在一起以后,就是处理这个数组的问题了,其实也不难,也就是如果存在两个相邻的,如a,a+1,就把它们合并成a+2,还有就是如果有两个a,则分成a-2和a+1。/* * hdu3818cpp/win.cpp * Created on: 2012-10-28 * Author : ben */#include <cstdio>#include <cstdlib>
阅读全文
摘要:挺简单,直接上代码。/* * hdu2062/win.cpp * Created on: 2012-10-27 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>
阅读全文
摘要:就是建图,把题目描述的东东转换成一张图求最短路就行了,因为是随机询问,所以用floyd比较方便。不过打完之后一直WA,百思不得其解的情况下看了一下discuss,有人说得用long long,于是我马上改了交,果然过了……唉,以后看题还是得细心……/* * hdu1690/win.cpp * Created on: 2012-10-27 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime&g
阅读全文
摘要:这题还是挺不错的,第一个突破点就是n很大但是m很小,所以能组成的集合最多有2^14种的,枚举这每一种能否构成即可。刚开始的时候是用set存每一个数的,超时,略加改进,用位存储就过掉了。不过我还是算蹭过的,600多ms,应该还能继续用位运算优化。/* * hdu3306/win.cpp * Created on: 2012-10-27 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>
阅读全文
摘要:刚看的时候还以为挺难的,试了一下最水的方法,居然过了。就是从N以后往下试,试到smith数停止就行,而且对于smith数的判断也可以简单处理,循环到sqrt(n)即可,唉,这种简单方法我这次现场赛咋没想到呢……/* * hdu1333/win.cpp * Created on: 2012-10-27 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iost
阅读全文
摘要:这题第一个突破点是:由于第i个城市建加油站需2^(i-1),这比前i-1个城市都建加油站耗费的还多,所以可以倒过来枚举,如果前n-1城市都建加油站而第n个城市不建能满足要求的话,那么最终结果肯定是不需要在n建加油站的,否则就需要建;接下来继续考虑在这种情况下前n-2个城市全建、n-1不建是否能满足要求,进而确定n-1城市的状态。依此类推,就能用O(N)的时间确定每一个城市是否建站的状态。对于一个确定的状态,用广搜进行判断即可,不过细节还是挺多的,例如有些城市(不建加油站)可以从加油站过去,但是无法再次回到加油站。比赛的时候代码不是我打的,也没有打印带回来,现在懒得再打一次贴上来了,有时间再说吧
阅读全文
摘要:枚举r,二分K就可以了,不过还是需要注意细节,比较数据类型之类的,不然容易错。/* * hdu4430/win.cpp * Created on: 2012-10-26 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include &
阅读全文
摘要:题目还是挺简单的,就是硬算,先求出N的所有因数,然后一个个地加起来,最后再处理输出就行了。现场赛的时候,模板准备不足,这题居然打了一个多小时,唉,要是能早交20分钟,银牌就妥妥的了……杯具……/* * hdu4432/win.cpp * Created on: 2012-10-26 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#
阅读全文
摘要:暴搜就可以过了,简单。/* * hdu2181/win.cpp * Created on: 2012-10-25 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map&g
阅读全文
摘要:比较简单的计算几何,首先枚举两个在圆上的点,然后数一数多少个点在此圆上,复杂度n^3。但是要注意的是如果这样得到的结果是0,那么还是要输出1,因为至少可以捞一条鱼,这是一个易错点!/* * hdu1077/win.cpp * Created on: 2012-10-25 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#includ
阅读全文
摘要:又是一道不会的题,但是猜想答案就是n,交上去居然也过了,但是还是不理解为什么,求大牛指导……/* * hdu1295/win.cpp * Created on: 2012-10-25 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#in
阅读全文
摘要:这题还是不错了,刚看到这题的时候感觉是不会,但是后来用笔算出了几个数的结果之后,发现这种手算的方法可以用程序模拟出来,也就是首先穷举A的第K位被抽掉,那么就可以把A分成三部分,K位之前的部分a,第K位b和第K位之后的c,于是c只有两种情况,进位或者不进位,而b也只有两种情况,进位或不进位,判断一下就可以了。/* * hdu1271/win.cpp * Created on: 2012-10-24 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <
阅读全文
摘要:为了学习STL,全用STL实现的,代码省了不少。/* * hdu1216/win.cpp * Created on: 2012-10-24 * Author : ben */#include <cstdio>#include <cstdlib>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>#include
阅读全文
摘要:应该说是道简单的几何题,可是我推公式还是推了半天,主要就是斜着放的情况吧,刚开始推的公式不对,wa了几次。/* * hdu1110/win.cpp * Created on: 2012-10-24 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue
阅读全文
摘要:这题其实我不会,随便找了几个特例算算觉得答案可能是(n-1)/2就打了交,居然过了。可是不太理解这种做法的正确性,上网搜一下,也没人写解题报告,改天问问老师去……/* * hdu1273/win.cpp * Created on: 2012-10-23 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <alg
阅读全文
摘要:找出足够的相遇或追及的时间,排个序输出就可以了。/* * hdu1275/win.cpp * Created on: 2012-10-23 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#incl
阅读全文
摘要:这题真杯具,比赛的时候没做出来,虽然也是贪心的方法,但想复杂了。其实就分两种情况比较,一种是不杀带武器的人,直接把不带武器的排个序杀就是了;第二种为杀带武器的,那么带武器的是得全部杀掉的,先用耐力值杀掉消耗最小的那个带武器的人,然后数一数总的武器数,把剩下的人按消耗值排序,留下武器总数个的人,其余的用耐力值尽量杀就行了,so easy啊,真杯具。。。/* * hdu4415/win.cpp * Created on: 2012-10-9 * Author : ben */#include <cstdio>#include <cstdlib>#include <cs
阅读全文
浙公网安备 33010602011771号