随笔分类 -  找规律或推公式

摘要:这题的结果[f(1)+f(2)+...+f(n)]其实就等价于x*y*z<=n的解的个数,然后的方法几乎就是暴力枚举了。现场比赛的时候没想到这一点,太杯具了,浪费了两个小时的思考时间。其实我们的做法应该是可行的,因为f(n)具有积性性质,也就是若gcd(n, m)=1,则f(n*m)=f(n)*f(m)。而当p为质数时,f(p^k)=(k+1)*(k+2)/2,这样就能把f(n)数列的前n项和化成一堆多项式的加和。然后用合并同类项的思想,用容斥原理搞,可是代码量太大了,没打出来。。。今天赛题被挂到HDOJ上以后用上面说的枚举方法打了一下,交上去居然WA,调了半天也没发现错误,最后才怀疑是 阅读全文
posted @ 2012-11-12 16:53 moonbay 阅读(370) 评论(0) 推荐(0)
摘要:这题刚开始是没思路,后来觉得是DP,连DP方程都想出来,还考虑了各种优化方法,可是觉得实现难度有点大,所以先查解题报告。。。。结果一查,网上有人的代码异常简单,只有几行代码,所以马上意识到考虑复杂了,转而找规律,才算了几组,规律就出来了,就是1/(m*k+1+k)。so easy?/* * hdu4015/win.cpp * Created on: 2012-11-8 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#inc 阅读全文
posted @ 2012-11-09 00:12 moonbay 阅读(228) 评论(0) 推荐(0)
摘要:挺简单。假设我们现在面对两个要排的队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 & 阅读全文
posted @ 2012-10-30 10:55 moonbay 阅读(344) 评论(0) 推荐(0)
摘要:又是一道不会的题,但是猜想答案就是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 阅读全文
posted @ 2012-10-25 20:18 moonbay 阅读(276) 评论(0) 推荐(0)
摘要:应该说是道简单的几何题,可是我推公式还是推了半天,主要就是斜着放的情况吧,刚开始推的公式不对,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 阅读全文
posted @ 2012-10-24 14:27 moonbay 阅读(181) 评论(0) 推荐(0)
摘要:这题其实我不会,随便找了几个特例算算觉得答案可能是(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 阅读全文
posted @ 2012-10-23 21:00 moonbay 阅读(133) 评论(0) 推荐(0)
摘要:找出足够的相遇或追及的时间,排个序输出就可以了。/* * 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 阅读全文
posted @ 2012-10-23 19:55 moonbay 阅读(164) 评论(0) 推荐(0)
摘要:这题真杯具,比赛的时候没做出来,虽然也是贪心的方法,但想复杂了。其实就分两种情况比较,一种是不杀带武器的人,直接把不带武器的排个序杀就是了;第二种为杀带武器的,那么带武器的是得全部杀掉的,先用耐力值杀掉消耗最小的那个带武器的人,然后数一数总的武器数,把剩下的人按消耗值排序,留下武器总数个的人,其余的用耐力值尽量杀就行了,so easy啊,真杯具。。。/* * hdu4415/win.cpp * Created on: 2012-10-9 * Author : ben */#include <cstdio>#include <cstdlib>#include <cs 阅读全文
posted @ 2012-10-10 10:12 moonbay 阅读(188) 评论(0) 推荐(0)
摘要:/* * hdu2175/win.cpp * Created on: 2012-8-2 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>#include &l 阅读全文
posted @ 2012-08-02 02:40 moonbay 阅读(168) 评论(0) 推荐(0)
摘要:其实这题我不会,看了解题报告才做出来。突破点就是0068要找与elnil同角速度的同心圆。在同心圆上,2人的角速度是一样的;而在同心圆内,0068的角速度一直大于elnil的角速度,所以0068可以与elnil在大圆的一条直径上并且使距离达到最大程度。一旦0068到达同心圆上,便直线前进,以保证最快到岸,而此时elnil要走的距离依然是PI*R;/* * hdu1593/win.cpp * Created on: 2012-7-23 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstr 阅读全文
posted @ 2012-07-23 16:20 moonbay 阅读(154) 评论(0) 推荐(0)
摘要:这题严格来说我不会,不过看完题第一反应就是直接看第一个数是如何变化的,然后我就打了个小函数,打完以后交上去准备继续测试找规律,结果一看居然直接就AC了。。。太假了。。#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int getM(int N) { int i = 1; int ret = 1; while(i != N + 1) { ret++; if(i <= N) { i = i * 2... 阅读全文
posted @ 2012-07-18 18:50 moonbay 阅读(125) 评论(0) 推荐(0)
摘要:不知道大牛们有没有简洁的方法,反正我是一步一步慢慢推公式做出来的。居然推了一下午啊,囧。。。真是老了不中用了。。。其实推完后再整理整理,发现还是挺简单的,其实就是几个数列而已数列①1, 2, 3, 4, 5, 6, 7, 8, 。。。数列②1, 3, 6, 10, 15, 21, 28, 36。。。数列③1, 4, 10, 20, 35, 56, 。。。数列④1, 5, 15, 35, 70数列⑤3, 10, 21, 36,。。。数列⑥1, 6, 15, 28, 。。。我主要是把问题进行分解,三角形个数=正放三角形个数+倒放三角形个数正放三角形个数=边长为1的正放三角形个数+边长为2的正放三角 阅读全文
posted @ 2012-07-15 21:42 moonbay 阅读(248) 评论(0) 推荐(0)
摘要:其实是很简单的题,用定积分得到公式就行了,不过大学都毕业了我居然还会求定积分,忍不住想自夸一下^_^。。。/* * hdu1724/win.cpp * Created on: 2012-7-6 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue&g 阅读全文
posted @ 2012-07-06 16:13 moonbay 阅读(164) 评论(0) 推荐(0)
摘要:刚做完一道推公式题,这题跟上一题解题思路很像。做完后上网搜索,发现有些人不是我这样做的,他们是发现了结果中有循环节,不过我还是觉得我的做法更巧妙。我的做法如下:首先推出公式f(n)=cell[(n+1)*(n+1)*(2n-1)/4];这里涉及浮点数向上取整问题,将会给取余操作带来很大的麻烦,于是分类讨论之,我们记g(n)=(n+1)*(n+1)*(2n-1)。显然,当n为奇数时,g(n)能被4整除当n为偶数时,我们将g(n)等价转换为:n*n*(2n-1)+4*n*n-1,于是结论就显然了,g(n)+1一定能被4整除,这正是结果向上取整后的结果。接下来就用我上一题的方法如法炮制就行了。/* 阅读全文
posted @ 2011-10-28 21:47 moonbay 阅读(245) 评论(0) 推荐(0)
摘要:找规律的题目。如果不是圆环形状的话(也就是n个人排成直线),完全调换顺序需要(n-1)*n/2次交换;为环形的时候,可能不需要这么多,因为调换有了两个方向。我们记直线时n个人需要的交换次数为g(n)=(n-1)*n/2,显然g(n)是以n的平方增长的,所以要使总的交换次数尽量少,最佳情况就是将n分成尽量平均的两部分,分别向两个方向交换。/* * hdu1214/win.cpp * Created on: 2011-10-12 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring& 阅读全文
posted @ 2011-10-12 21:57 moonbay 阅读(206) 评论(0) 推荐(0)
摘要:其实还是汉诺塔问题,给你一个状态,问是否是正确状态转移过程中的状态。当盘子数为n时,只需要看最大的盘子在哪根柱子上,三种情况分别递归判断即可~/* * hdu1997/win.cpp * Created on: 2011-10-9 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <queue># 阅读全文
posted @ 2011-10-09 17:11 moonbay 阅读(229) 评论(0) 推荐(0)
摘要:简单的找规律题,假设连续序列为a, a+1, a+2,...,a+k则(2*a+k)*(k+1)/2=N,从而a可以用N和k表示出来,而通过这个公式能够发现k一定小于sqrt(2*N+1),枚举k,计算出a判断是否符合题意即可。/* * hdu1868/win.cpp * Created on: 2011-10-8 * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#incl 阅读全文
posted @ 2011-10-08 14:27 moonbay 阅读(224) 评论(0) 推荐(0)
摘要:这题没啥,知道公式或者能推出来即可,公式放在这里备忘。M(n)=(n-1)[M(n-2)+M(n-1)] 特殊地,M(1)=0,M(2)=1 阅读全文
posted @ 2011-09-30 19:21 moonbay 阅读(88) 评论(0) 推荐(0)
摘要:找规律推公式的题目,公式挺简单的,就是(2 * n)!/(n!)*(n!)*4^n不过因为有用到大数,还是用java比较方便import java.math.BigInteger;import java.util.Scanner;public class Main { public static void work(int n) { BigInteger up = BigInteger.ONE; for (int i = 2; i <= 2 * n; i++) { up = up.multiply(BigInteger.valueOf(i... 阅读全文
posted @ 2011-09-21 10:02 moonbay 阅读(150) 评论(0) 推荐(0)
摘要:这题本来应该是推公式做的,我一时没推出来,就全用二分查找了,打的时候没注意,提交的时候才发现ME,想了一想,杭电数据向来很弱的,就把MAXN改成1000000,过了,无语!/* * hdu2446/win.c * Created on: 2011-8-20 * Author : ben */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#define MAXN 5496092long long array[MAXN], sum[MAXN];void 阅读全文
posted @ 2011-08-20 16:58 moonbay 阅读(243) 评论(0) 推荐(0)