随笔分类 -  HDOJ

发布一些HDOJ的做题情况以及代码。
[恢]hdu 2114
摘要:2011-12-16 02:11:23地址:http://acm.hdu.edu.cn/showproblem.php?pid=2114题意:算前n项立方和的末4位。mark:立方和公式:n^2(n+1)^2/4。注意取mod和溢出处理。代码:# include <stdio.h>int main (){ long long n ; int ans ; while (~scanf ("%I64d", &n)) { n %= 10000 ; ans = (n*n*(n+1)*(n+1)/4) % 10000 ; printf ("... 阅读全文

posted @ 2012-01-06 16:38 Seraph2012 阅读(105) 评论(0) 推荐(0)

[恢]hdu 1465
摘要:2011-12-16 02:01:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=1465题意:中文。。mark:错拍问题。。。递推。dp[i] = (i-1) * (dp[i-1] + dp[i-2])代码:# include <stdio.h># include <string.h>long long dp[25] = {0, 0, 1} ;int main (){ int i ; for(i = 3 ; i <= 20 ; i++) dp[i] = (i-1)*(dp[i-1]+dp[i-2]) ; while. 阅读全文

posted @ 2012-01-06 16:37 Seraph2012 阅读(143) 评论(0) 推荐(0)

[恢]hdu 1860
摘要:2011-12-16 01:56:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=1860题意:中文。。。直接爆。代码:# include <stdio.h># include <string.h>int main (){ int i, j, tab[10] ; char s1[10], s2[100] ; while (gets(s1)) { if (strcmp(s1, "#") == 0) break ; gets (s2) ; memset (tab, 0, sizeof(t... 阅读全文

posted @ 2012-01-06 16:36 Seraph2012 阅读(154) 评论(0) 推荐(0)

[恢]hdu 1570
摘要:2011-12-16 01:50:33地址:http://acm.hdu.edu.cn/showproblem.php?pid=1570题意:算排列&组合数。数据忒小,不用考虑溢出。代码:# include <stdio.h>int factorial[15] = {1, 1} ;int main (){ int i, T, a, b ; char ch ; for(i = 2 ; i <= 10 ; i++) factorial[i] = factorial[i-1] * i ; scanf ("%d%*c", &T) ; while ( 阅读全文

posted @ 2012-01-06 16:35 Seraph2012 阅读(175) 评论(0) 推荐(0)

[恢]hdu 1555
摘要:2011-12-16 01:37:28地址:http://acm.hdu.edu.cn/showproblem.php?pid=1555题意:中文。。。mark:2WA,老老实实模拟,想用除法和取mod算,必死。不可借钱,但是结果可以迭代。代码:# include <stdio.h>int main (){ int m, k, ans ; while (~scanf ("%d%d", &m, &k) && (m||k)) { ans = 0 ; while (m) { ans ++ ; m-... 阅读全文

posted @ 2012-01-06 16:34 Seraph2012 阅读(147) 评论(0) 推荐(0)

[恢]hdu 1262
摘要:2011-12-16 01:03:32地址:http://acm.hdu.edu.cn/showproblem.php?pid=1262题意:中文,验证哥德巴赫猜想。mark:wa一次,例如6 = 3+3这种,3,3居然也算素数对。。。。代码:# include <stdio.h>int n, a, b ;int IsPrime(int p){ int i ; for (i = 2 ; i < p ; i++) if (p%i==0) return 0 ; return 1 ;}void gao(int n){ int p, q ; p = n/2,... 阅读全文

posted @ 2012-01-06 16:33 Seraph2012 阅读(158) 评论(0) 推荐(0)

[恢]hdu 1210
摘要:2011-12-16 00:57:22地址:http://acm.hdu.edu.cn/showproblem.php?pid=1210题意:中文。。。mark:枚举了”1“的变化位置,然后计数。当1回到第一位,则停止。代码:# include <stdio.h>int calc(int n){ int cnt = 0, cur = 1 ; do{ if (cur <= n) cur = 2*cur ; else cur = (cur-n) * 2 - 1 ; cnt++ ; }while (cur != 1) ; return... 阅读全文

posted @ 2012-01-06 16:32 Seraph2012 阅读(188) 评论(0) 推荐(0)

[恢]hdu 1235
摘要:2011-12-16 00:13:46地址:http://acm.hdu.edu.cn/showproblem.php?pid=1235题意:中文。。。代码:# include <stdio.h>int a[1010], num, n ;int main (){ int ans, i ; while (~scanf ("%d", &n) && n) { for (i = 0 ; i < n ; i++) scanf ("%d", &a[i]) ; scanf ("%d", &n 阅读全文

posted @ 2012-01-06 16:19 Seraph2012 阅读(186) 评论(0) 推荐(0)

[恢]hdu 1229
摘要:2011-12-16 00:08:13地址:http://acm.hdu.edu.cn/showproblem.php?pid=1229题意:中文。。。代码:# include <stdio.h>int test(int a, int b, int k){ while (k--) { if (a%10 != b%10) return 0 ; a /= 10 ; b /= 10 ; } return 1 ;}int main (){ int a, b, k ; while (~scanf ("%d%d%d", &a, ... 阅读全文

posted @ 2012-01-06 16:18 Seraph2012 阅读(125) 评论(0) 推荐(0)

[恢]hdu 1097
摘要:2011-12-15 23:49:02地址:http://acm.hdu.edu.cn/showproblem.php?pid=1097题意:求a的b次方的最后一个数字。mark:数论公式,b = b%4+4。直接暴力。不需要快速幂。代码:# include <stdio.h>int qpow(int a, int b){ int i, mul = 1 ; for (i = 0 ; i < b ; i++) mul = mul * a % 10 ; return mul ;}int main (){ int a, b ; while (~scanf ... 阅读全文

posted @ 2012-01-06 16:17 Seraph2012 阅读(149) 评论(0) 推荐(0)

[恢]hdu 1170
摘要:2011-12-15 23:53:54地址:http://acm.hdu.edu.cn/showproblem.php?pid=1170题意:四则运算。。。代码:# include <stdio.h>int main (){ int T, a, b ; char op ; scanf ("%d%*c", &T) ; while(T--) { scanf ("%c %d %d%*c", &op, &a, &b) ; if (op == '+') printf ("%d\n", 阅读全文

posted @ 2012-01-06 16:17 Seraph2012 阅读(138) 评论(0) 推荐(0)

[恢]hdu 1040
摘要:2011-12-15 23:42:25地址:http://acm.hdu.edu.cn/showproblem.php?pid=1040题意:给n个数,排序后输出。代码:# include <stdio.h># include <stdlib.h>int a[1010] ;int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b ;}int main (){ int i, T, n ; scanf ("%d", &T) ; while (T--) { scanf (&q 阅读全文

posted @ 2012-01-06 16:08 Seraph2012 阅读(139) 评论(0) 推荐(0)

[恢]hdu 1076
摘要:2011-12-15 22:56:08地址:http://acm.hdu.edu.cn/showproblem.php?pid=1076题意:求y之后第n个闰年是哪年(如果y是闰年,y算第一年)。代码:# include <stdio.h>int IsLeap(int y){ if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) return 1 ; return 0 ;}int nextleapyear(int y){ int rtn = y+1 ; while (!IsLeap(rtn)) rtn++ ; ... 阅读全文

posted @ 2012-01-06 16:07 Seraph2012 阅读(142) 评论(0) 推荐(0)

[恢]hdu 1064
摘要:2011-12-15 15:06:33地址:http://acm.hdu.edu.cn/showproblem.php?pid=1064题意:求12个数的平均数- -。代码:# include <stdio.h>int main (){ int i ; double sum = 0, num ; for (i = 0 ; i < 12 ; i++) { scanf ("%lf", &num) ; sum += num ; } printf ("$%.2lf\n", sum/12.0) ; return 0 ;} 阅读全文

posted @ 2012-01-06 16:04 Seraph2012 阅读(100) 评论(0) 推荐(0)

[恢]hdu 1049
摘要:2011-12-15 14:49:48地址:http://acm.hdu.edu.cn/showproblem.php?pid=1049题意:有个蜗牛,每分钟向上爬u,第二分钟休息,下滑d。问几分钟能爬到n长的杆顶。mark:肯定是有公式,但处理边界麻烦,直接模拟。代码:# include <stdio.h>int main (){ int n, u, d, minutes, cur ; while (~scanf ("%d%d%d", &n, &u, &d) && (n||u||d)) { cur = 0, minute 阅读全文

posted @ 2012-01-06 16:03 Seraph2012 阅读(117) 评论(0) 推荐(0)

[恢]hdu 1062
摘要:2011-12-15 15:02:44地址:http://acm.hdu.edu.cn/showproblem.php?pid=1062题意:倒序单词输出。mark:wa了一次,把范围1000看成100, 2B了。代码:# include <stdio.h>char str[1100] ;char word[1100] ;void gao(char str[]){ word[100] = '\0' ; int i, cnt = 99 ; for (i = 0 ; str[i] ; i++) { if (str[i] == ' ') { ... 阅读全文

posted @ 2012-01-06 16:03 Seraph2012 阅读(154) 评论(0) 推荐(0)

[恢]hdu 2115
摘要:2011-12-15 14:45:28地址:http://acm.hdu.edu.cn/showproblem.php?pid=2115题意:nba技巧赛,输入人名,分钟,秒钟。按时间少到多排序,并输出rank。mark:PE一次,每组case之间空一行。代码:# include <stdio.h># include <stdlib.h># include <string.h> typedef struct NODE{ char name[50] ; int mm, ss ;}NODE ;NODE node[20] ;int cmp(const void * 阅读全文

posted @ 2012-01-06 16:01 Seraph2012 阅读(161) 评论(0) 推荐(0)

[恢]hdu 2520
摘要:2011-12-15 14:28:07地址:http://acm.hdu.edu.cn/showproblem.php?pid=2520题意:中文。。。找规律,n^2。注意long long。代码:# include <stdio.h> int main (){ long long n ; scanf ("%I64d", &n) ; while (~scanf ("%I64d", &n)) { n = n*n % 10000 ; printf ("%I64d\n", n) ; } return 0 ;} 阅读全文

posted @ 2012-01-06 15:59 Seraph2012 阅读(135) 评论(0) 推荐(0)

[恢]hdu 2123
摘要:2011-12-15 07:04:57地址:http://acm.hdu.edu.cn/showproblem.php?pid=2123题意:做一个N*N的乘法表,第i行第j个表示i*j。代码:# include <stdio.h>int main (){ int n, i, j ; scanf ("%d", &n) ; while (~scanf ("%d", &n)) { for (i = 1 ; i <= n ;i++) { for (j = 1 ; j <= n ;j++) if (... 阅读全文

posted @ 2012-01-06 15:55 Seraph2012 阅读(137) 评论(0) 推荐(0)

[恢]hdu 2030
摘要:2011-12-15 07:08:43地址:http://acm.hdu.edu.cn/showproblem.php?pid=2030题意:中文。汉字的ascii码二进制最高位是1。代码:# include <stdio.h>char str[1100] ;int calc (char str[]){ int i, sum = 0 ; for (i = 0 ; str[i] ; i++) if (str[i] & 0x80) sum++, i++ ; return sum ;}int main (){ int T ; scanf ("%d%*c",.. 阅读全文

posted @ 2012-01-06 15:55 Seraph2012 阅读(108) 评论(0) 推荐(0)