摘要: 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 阅读(328) 评论(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 阅读(428) 评论(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 阅读(382) 评论(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 阅读(225) 评论(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 阅读(376) 评论(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 阅读(300) 评论(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 阅读(832) 评论(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 阅读(255) 评论(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 阅读(236) 评论(0) 推荐(0) 编辑
摘要: voidmn(intn ){for(inti = 0; i <= n; ++i ){m1[i] = 1;m2[i] = 0;}for(inti = 2; i <= n; ++i )//难点{//总共有n个括号,从第2个起每一个括号都要和前面那一个括号相乘//所以可以忽略第一个括号for(intj = 0; j <= n; ++j )//j代表最前面这个大括号的项数for(intk = 0; k + j <= n; k += i )//在大括号后面,x都是以i方递增的m2[j + k] += m1[j];//这里就是大括号后面的括号与前面相乘的计算for(intj = 0 阅读全文
posted @ 2011-08-07 15:38 ○o尐懶錨o 阅读(187) 评论(0) 推荐(0) 编辑