随笔分类 -  水题系列

大多是hdu11页的题目吧
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2104这道题看很久啊,意思是n个人围成一个圈,大家玩丢手帕游戏,手帕藏在某一个人的箱子里,Haha来找,每一次他都会跳过m-1个人。问你Haha是不是一定能找到手帕。因为Haha找的次数是无限的,可以永远找下去,所以,只要他能把所有的人都找一遍就一定能找到。但按照他的这种找法,如果n和m不互质的话,不互质就会出现某些人是永远不会找。所以看一下 n和m的最大公约数就行了代码:#include <stdio.h>#include <string.h>#include <stdlib. 阅读全文
posted @ 2011-08-13 21:05 ○o尐懶錨o 阅读(1196) 评论(1) 推荐(1)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1008这是一道简单题,是一道模拟电梯上下,直接计算就可以了代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int a[100],n,sum; while(scanf("%d",&n),n) { a[0]=0;sum=0; for(int i=1;i<=n;++i) { scanf("%d&qu 阅读全文
posted @ 2011-08-13 20:12 ○o尐懶錨o 阅读(153) 评论(0) 推荐(1)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1049这是一道简单题,其实题目很简单,就是一条虫,每步爬u,休息的时候下滑d,知道虫子爬出n的距离,直接模拟就可以了,不过判断时注意一点,就是最后一步不休息也可以。。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int n,u,d,sum,k; while(scanf("%d%d%d",&n,&u, 阅读全文
posted @ 2011-08-13 20:10 ○o尐懶錨o 阅读(252) 评论(0) 推荐(1)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2067这是一道卡特兰数,请看资料:http://baike.baidu.com/view/2499752.htm其实就是应用代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int m,i,j,t=0; __int64 a[40][40]; while(scanf("%d",&m),m!=-1) { t++; 阅读全文
posted @ 2011-08-12 19:55 ○o尐懶錨o 阅读(404) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2065据说这是一个母函数指数型,可是我看了半天觉得还是没有感觉,觉得还是递推比较好,直接看代码可能不懂,但是推理过程太麻烦。。。就是从n-1个来确定第n个,这样一步一步找到规律代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ __int64 n; int t; int a[23]={0,2,6,20,72,72,56,60,12,92,5 阅读全文
posted @ 2011-08-12 18:06 ○o尐懶錨o 阅读(724) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2068这是一道错排题,不过有点变形,要把所以的你n/2的情况直接相加就可以了#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>__int64 mm(int x,int y){ __int64 sum=1; for(int i=x;i>=x-y+1;--i) sum*=i; for(int j=y;j>=2;--j) sum/=j; return sum;} 阅读全文
posted @ 2011-08-11 21:10 ○o尐懶錨o 阅读(211) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2045a(1)=3;a(2)=6;a(3)=6;a(4)=18;现在考虑n>3的情况,若第n-1个格子和第一个格子不同,则为a(n-1);若第n-1个格子和第1个格子相同,则第n-2个格子和第一个格子必然不同,此时为a(n-2)再乘第n-1个格子的颜色数,很显然第n-1个格子可以是第一个格子(即第n-2个格子)的颜色外的另外两种,这样为2*a(n-2);#include <stdio.h>#include <string.h>#include <stdlib.h>#i 阅读全文
posted @ 2011-08-11 18:04 ○o尐懶錨o 阅读(236) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2049这是一道错排题,可是比赤裸裸的要多一点东西。因为m个人错排,可是不知道是哪m个错排,所以要用到高中排列组合,即调用函数的公式:代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>__int64 mm(int x,int y){ __int64 sum=1; for(int i=x;i>=x-y+1;--i) sum*=i; for(int j=y;j& 阅读全文
posted @ 2011-08-11 15:51 ○o尐懶錨o 阅读(602) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2058观察a+1,a+2…a+d全部相加等于m即(a+1+a+d)*d/2 = m,这里d是平方,我们可以从长度d入手,当a+1,a+2…a+3相加等于m时,即(a+1+a+d)*d/2 = m而a最小是0,所以(d+1)*d/2=m时d去最大值,就是这步把时间复杂度减小的。d就是sqrt(2*m),(a+1+a+d)*d/2 = m,所以a*d + (d+1)*d/2 = m,所以要使等式成立,m-(d+1)*d/2必须是d的倍数。代码:#include <stdio.h>#include &l 阅读全文
posted @ 2011-08-09 15:55 ○o尐懶錨o 阅读(334) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2073这是一道分段处理题,第一步先把斜率为1的线段处理好:sum+=a*(a-1)*sqrt(2.0)/2; 第二步把线段斜率不为1的处理好:for(int i=a;i>0;--i)sum+=sqrt(i*i+(i-1)*(i-1)); 第三步把包括该点的线段加入:sum+=(a-y)*sqrt(2.0); 最后用前面的点与后面的点去差的绝对值。。。#include <stdio.h>#include <string.h>#include <stdlib.h>#inc 阅读全文
posted @ 2011-08-09 10:48 ○o尐懶錨o 阅读(436) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2051这题就是简单的求二进制的值,我本来打算找一个%。。的可是没有找,只有8进制%o,十六进制%x;所以只有写代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int n,k,r,a[50]; while(scanf("%d",&n)!=EOF) { k=0; while(n) { r=n%2; a[k++]= 阅读全文
posted @ 2011-08-08 20:26 ○o尐懶錨o 阅读(389) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2055这是一道简单题,就是用它们字符想减的值就可以了,相信程序很容易看懂,我也不多说了#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ char a[10]; int n,y,k; scanf("%d",&n); while(n--) { scanf("%s%d",&a,&y); 阅读全文
posted @ 2011-08-08 19:56 ○o尐懶錨o 阅读(229) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2076这是一道关于计算的题,秒会影响分,分会影响时,所以关系要理清楚,时:e=(a%12)*30+0.5*b+0.5/60*c;(注意是24小时制%12后就可以避免) 分:d=b*6+0.1*c;还有注意取整数不可以用%.0lf,会自动四舍五入,所以要强制转化为int就可以了代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ int n,a 阅读全文
posted @ 2011-08-08 17:46 ○o尐懶錨o 阅读(387) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2046这是一道递推题目,只要列举1到7就可以了,我们会发现:1-1,2-2,3-3,4-5,5-8,6-13,7-21。。。。。不过这里要小心50时定义时要用——int64#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int main(){ __int64 a[60];int n; a[1]=1;a[2]=2; for(__int64 i=3;i<=50;+ 阅读全文
posted @ 2011-08-08 16:03 ○o尐懶錨o 阅读(306) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2093这道题目昨天做到今天啦,总算ac了,这道题目其实不难,只是有点麻烦,先按做的数目排序,然后再按和从小到大排序,最后还要按字典序排序,最后还有格式的控制,其实处理括号的时可以用sscanf(字符串首地址(不用引号),"%d(%d)",&a,&b),它返回的是输入数据的个数,其实sscanf与scanf的区别就是前者是已经输入的字符串中读入,后者是从键盘输入,返回的都是输入的个数下面是没有用sscanf的代码:#include <stdio.h>#includ 阅读全文
posted @ 2011-08-08 11:23 ○o尐懶錨o 阅读(844) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2074这道题目以前做过的,用调用函数将map一圈一圈的画,我觉得这个很容易理解先画最外面的一圈,直到x>y,也就是中间那个画完,可是注意有两点:1.注意当n=1的时候输去第一个,2.注意输出的格式,最后没有空行,我PE好多次,原来是把put("")写成了puts(" "),然后我把它改为printf("\n");就ac了,悲剧的一题啊#include <stdio.h>#include <string.h>#includ 阅读全文
posted @ 2011-08-07 17:21 ○o尐懶錨o 阅读(267) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2082一开始看题目很纠结,不知道如何入手,没想到母函数作用好广啊,排列组合方面也可以使用母函数解决,若有不清楚,请看母函数的解说,相信一看你就可以理解了,不过可以用母函数的一般都可以用背包,以下的是母函数的代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int m[28],c1[100],c2[100];void mhs(){ c1[0]=1;//一个入口 f 阅读全文
posted @ 2011-08-07 16:01 ○o尐懶錨o 阅读(242) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2048这是一道错排的变式,其实用错排(n!*(1/2!-1/3!+…..+(-1)^n/n!) )/全排(n!) 即是我们要求的百分率,如果要简单一点就可以直接用(1/2!-1/3!+…..+(-1)^n/n!),所以我们就可以很容易写出,还有精度问题,四舍五入,由于系统本身就是取的四舍五入,所以我们就可以不做处理了代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h&g 阅读全文
posted @ 2011-08-05 16:43 ○o尐懶錨o 阅读(461) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1465今天立神和我们讲了错排,才知道错排原来很简单,从第n个推起:当n个编号元素放在n个编号位置,元素编号与位置编号各不对应的方法数用M(n)表示,那么M(n-1)就表示n-1个编号元素放在n-1个编号位置,各不对应的方法数,其它类推. 第一步,把第n个元素放在一个位置,比如位置k,一共有n-1种方法; 第二步,放编号为k的元素,这时有两种情况.1,把它放到位置n,那么,对于剩下的n-2个元素,就有M(n-2)种方法;2,不把它放到位置n,这时,对于这n-1个元素,有M(n-1)种方法; 综上得到 M(n)= 阅读全文
posted @ 2011-08-05 16:00 ○o尐懶錨o 阅读(215) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2080这个题目是求角度,用向量的方法求的cosx,cosx等于向量之积除以向量的模的积,相信公式大家都会吧,然后用acos(cosx)就可以达到角度的大小,这道题还要注意精度代码:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#define PI 3.141592653int main(){ int n; double x1,x2,y1,y2,m,t; scanf 阅读全文
posted @ 2011-08-04 13:49 ○o尐懶錨o 阅读(795) 评论(0) 推荐(1)