摘要:
2011-12-15 00:25:42地址:http://acm.hdu.edu.cn/showproblem.php?pid=2053题意:有无限多的电灯排成一列,一开始都是关,操作无限多次,第i次操作会把编号为i和i的倍数的电灯改变状态。问最后第i盏电灯的状态是开还是关。mark:TLE了一次,直接扫约数判奇偶结果TLE了。打表找规律,发现只要是平方数(1、4、9、16……)就是开,否则就是关。代码:# include <stdio.h># include <math.h>int main (){ int i, n, m ; while (~scanf (" 阅读全文
摘要:
2011-12-14 23:54:25地址:http://acm.hdu.edu.cn/showproblem.php?pid=2050题意:中文~mark:这题其实是Knuth老爹的《具体数学》1.2的一个例题。可以直接递推(dp[i] = dp[i-1]+4(i-1)+1),也可以用待定系数法求ax^2+bx+c的系数,总之怎么搞都可以啦。代码:# include <stdio.h>int dp[10010] = {1} ;int main (){ int i ; for (i = 1; i<=10000 ;i ++) dp[i] = dp[i-1] + 4*(i... 阅读全文
摘要:
2011-12-15 00:03:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=2051题意:输入十进制n,输出n的二进制。mark:注意n=0的情况。代码:# include <stdio.h>void output(int n){ if (n == 0) return ; output (n>>1) ; putchar ((n&1) + '0') ;}int main (){ int n ; while (~scanf ("%d", &n)) { if (n == 0 阅读全文
摘要:
2011-12-14 20:45:44地址:http://acm.hdu.edu.cn/showproblem.php?pid=2047题意:中文。mark:递推,dp[i] = (dp[i-1]+dp[i-2]) * 2。要用long long代码:# include <stdio.h>long long dp[45] = {1, 3} ;int main (){ int i ; for (i = 2 ; i <= 40 ; i++) dp[i] = (dp[i-1]+dp[i-2]) * 2 ; while (~scanf ("%d", &i) 阅读全文
摘要:
2011-12-14 20:35:58地址:http://acm.hdu.edu.cn/showproblem.php?pid=2034题意:中文。。mark:用了qsort和bsearch,蛮好用的。代码:# include <stdio.h># include <stdlib.h>int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b ;}int a[110], b[110] ;int main (){ int i, cnt, flag ; int n, m ; while (~scanf 阅读全文
摘要:
2011-12-14 20:24:33地址:http://acm.hdu.edu.cn/showproblem.php?pid=2044题意:中文。mark:递推,考虑a和b的差,注意要long long。代码:# include <stdio.h>int main (){ int n, m, i ; long long dp[55] = {1, 1} ; for (i = 2 ; i <= 50 ; i++) dp[i] = dp[i-1]+dp[i-2] ; scanf ("%d", &n) ; while (~scanf ("%d% 阅读全文
摘要:
2011-12-14 06:19:27地址:http://acm.hdu.edu.cn/showproblem.php?pid=2046题意:中文。。。mark:递推,dp[i] = dp[i-1] + dp[i-2]。要用long long代码:# include <stdio.h>long long dp[60] = {0, 1, 2} ;int main (){ int i, n ; for (i = 3 ; i <= 50 ; i++) dp[i] = dp[i-1] + dp[i-2] ; while (~scanf ("%d", &n) 阅读全文
摘要:
2011-12-14 06:20:00纪念一下~~。前50题中,1002稍微麻烦点吧。其它的都还好啦。 阅读全文
摘要:
2011-12-14 06:08:05地址:http://acm.hdu.edu.cn/showproblem.php?pid=1002题意:a+b,不过是大数的。1000位十进制。mark:大数加法,不是很难写。1Y。代码:# include <stdio.h># include <string.h>char s1[1010], s2[1010], s3[1010] ;int a[1010], b[1010], buff[1010] ;void strtonum (char s[], int num[]){ int i ; num[0] = strlen(s) ; f 阅读全文
摘要:
2011-12-14 05:49:09地址:http://acm.hdu.edu.cn/showproblem.php?pid=2015题意:中文,忒麻烦了。代码:# include <stdio.h>int main (){ int n, m, flag ; int i, sum, cnt ; while (~scanf ("%d%d", &n, &m)) { flag = 0 ; cnt = 0 ; sum = 0 ; for (i = 1 ; i <= n ; i++) { ... 阅读全文