随笔分类 -  HDOJ

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 24 下一页

发布一些HDOJ的做题情况以及代码。
[恢]hdu 1944
摘要:2011-12-24 19:03:12地址:http://acm.hdu.edu.cn/showproblem.php?pid=1944题意:同1536。重复了。代码:# include <stdio.h># include <string.h>int sg[10010] ;int k, knum[110] ;int flag[110] ;int met(int n){ int i, ans = 0 ; memset (flag, 0, sizeof(flag)) ; for (i = 0 ; i < k ; i++) if (n - knum[i] >= 阅读全文

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

[恢]hdu 1865
摘要:2011-12-24 20:04:44地址:http://acm.hdu.edu.cn/showproblem.php?pid=1865题意:若干个1,可以选择相邻两个合并成2。问有多少种可能的结果。mark:考虑最后一个数是1或2,可得递推dp[i] = dp[i-1]+dp[i-2]。但是最大是200,大概是10^50,所以要用大数加法。代码:# include <stdio.h># include <string.h>int tab[210][50] = {{1, 1}, {1, 1}} ;char str[210] ;void add(int a[], int 阅读全文

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

[恢]hdu 1536
摘要:2011-12-24 18:56:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1536题意:有一个集合有S个数。玩N次取石子游戏,每次只能取S集合里的数个石子。求判先手胜负。mark:SG函数,NIM博弈标准题。先求SG值打表,之后一串异或就OK了。复杂度是100w。代码:# include <stdio.h># include <string.h>int sg[10010] ;int k, knum[110] ;int flag[110] ;int met(int n){ int i, ans = 0 ; memset 阅读全文

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

[恢]hdu 1848
摘要:2011-12-23 09:32:51地址:http://acm.hdu.edu.cn/showproblem.php?pid=1848题意:中文。mark:求SG值后,1秒钟变NIM。代码:# include <stdio.h># include <stdlib.h>int fib[] = {1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597} ;int sg[1010] = {0, 1} ;int cmp(const void *a, const void *b){ return *(in 阅读全文

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

[恢]hdu 1421
摘要:2011-12-24 12:13:01地址:http://acm.hdu.edu.cn/showproblem.php?pid=1421题意:有n样物品,每样物品有重量。要选k对,每对代价是俩物品重量差的平方。问怎么选总代价最小。mark:排序,然后按顺序dp。代码:# include <stdio.h># include <stdlib.h># include <string.h>int w[2010], a[2010] ;int dp[2010][1010] ;int min(int a, int b){return a<b?a:b;}int cm 阅读全文

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

[恢]hdu 1163
摘要:2011-12-23 09:17:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=1163题意:求n^n的数字根。mark:数字根其实就是9的余数。数论知识,n>6的时候,pow(n,n) = pow(n%9, n%6+6)。代码:# include <stdio.h>int pow(int a, int b){ int i, ans = 1 ; for (i = 0 ;i < b ; i++) ans = ans * a % 9 ; return ans % 9 ;}int main (){ int n, a... 阅读全文

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

[恢]hdu 1079
摘要:2011-12-23 08:57:38地址:http://acm.hdu.edu.cn/showproblem.php?pid=1079题意:给个日期(从1900-1-1开始的)。两个人轮流操作,每次可以把日期变成后一天,或者是下月的当天(若不存在,则不可变)。谁走到2001-11-4就赢。问先手有无必胜策略。mark:记忆化爆搜。代码:# include <stdio.h># include <string.h>int dp[2200][15][35] ;int month[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 阅读全文

posted @ 2012-01-06 23:31 Seraph2012 阅读(331) 评论(2) 推荐(0)

[恢]hdu 1284
摘要:2011-12-23 09:08:47地址:http://acm.hdu.edu.cn/showproblem.php?pid=1284题意:面额为1、2、3的硬币组成n有多少种。mark:标准母函数,不过用dp搞了。dp[i][j]表示前i种硬币组成面额j的情况数,有dp[i][j] = dp[i-1][j] + dp[i][j-i]。代码:# include <stdio.h>int dp[4][40000] ;int main (){ int i, j, n ; dp[0][0] = 1 ; for (i = 1 ; i <= 3 ; i++) for (... 阅读全文

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

[恢]hdu 2117
摘要:2011-12-23 08:04:50地址:http://acm.hdu.edu.cn/showproblem.php?pid=2117题意:问1/n的小数点后第m位是多少。高精度除法。代码:# include <stdio.h>int gao(int n, int m){ int i, dividend=1, quotient, remainder ; for (i = 0 ; i <= m ; i++) { quotient = dividend/n ; remainder = dividend % n ; dividend = ... 阅读全文

posted @ 2012-01-06 23:30 Seraph2012 阅读(205) 评论(0) 推荐(0)

[恢]hdu 2189
摘要:2011-12-23 08:29:57地址:http://acm.hdu.edu.cn/showproblem.php?pid=2189题意:中文。把n拆成素数和有几种拆法。mark:本是标准母函数,不过用dp也可以YY一下。dp[i][j]表示用最大不超过i的素数组成j有多少种方法。如果i不是素数,直接和i-1的情况相同,如果i是素数,有dp[i][j] = dp[i][j-i] + dp[i-1][j]代码:# include <stdio.h># include <string.h>int dp[200][200] ;int n ;int IsPrime[200] 阅读全文

posted @ 2012-01-06 23:30 Seraph2012 阅读(197) 评论(0) 推荐(0)

[恢]hdu 1042
摘要:2011-12-23 07:49:22地址:http://acm.hdu.edu.cn/showproblem.php?pid=1042题意:算n!。最高10000。1w的时候n!有不超过4w位(Log10(10000^10000) = 40000)。代码:# include <stdio.h># define MOD 10000int num[40000] ;void mul(int n){ int i, cc = 0 ; for (i = 1 ; i <= num[0] ; i++) { num[i] = num[i]*n + cc ; cc ... 阅读全文

posted @ 2012-01-06 23:29 Seraph2012 阅读(156) 评论(0) 推荐(0)

[恢]hdu 1390
摘要:2011-12-23 07:55:30地址:http://acm.hdu.edu.cn/showproblem.php?pid=1390题意:中文。水。代码:# include <stdio.h>int main (){ int T, i, n, flag ; scanf ("%d", &T) ; while (T--) { scanf ("%d", &n) ; flag = 0 ; for (i = 0 ; (1<<i) <= n ; i++) { if (n&(1<<i)) ... 阅读全文

posted @ 2012-01-06 23:29 Seraph2012 阅读(156) 评论(0) 推荐(0)

[恢]hdu 1849
摘要:2011-12-23 06:35:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1849题意:中文。mark:NIM博弈,SG函数,还是缺乏感性认识,wa了2次。代码:# include <stdio.h>int main (){ int n, sg, num ; while (~scanf ("%d", &n) && n) { sg = 0 ; while (n--) { scanf ("%d", &num) ; sg ^= num ; ... 阅读全文

posted @ 2012-01-06 23:28 Seraph2012 阅读(122) 评论(0) 推荐(0)

[恢]hdu 1517
摘要:2011-12-23 07:30:49地址:http://acm.hdu.edu.cn/showproblem.php?pid=1517题意:S和O玩游戏,S先动。一开始P=1,每次让它乘以2或9,超过n的获胜。问最后谁赢。mark:虽然是博弈。。。但是貌似很麻烦,直接记忆化爆之。。。代码:# include <stdio.h># include <string.h>int dp[40][40] ;long long n ;long long pow(int a, int b){ long long ans = 1 ; int i ; for (i = 0 ; i &l 阅读全文

posted @ 2012-01-06 23:28 Seraph2012 阅读(132) 评论(0) 推荐(0)

[恢]hdu 1850
摘要:2011-12-23 05:06:19地址:http://acm.hdu.edu.cn/showproblem.php?pid=1850题意:中文。mark:上一题(1847)是博弈,搜过了,这题还是博弈,迫不得已看了一下NIM博弈。假设数量是a1,a2,a3...an。令k = a1^a2^a3..^an。其中"^"表示异或。令ai' = ai ^ k。若ai' < ai,则表示ai这堆取成ai'可以让对方必败,即为先手的一种可行走法。代码:# include <stdio.h>int a[110] ;int main (){ i 阅读全文

posted @ 2012-01-06 23:27 Seraph2012 阅读(152) 评论(0) 推荐(0)

[恢]hdu 1846
摘要:2011-12-23 06:07:41地址:http://acm.hdu.edu.cn/showproblem.php?pid=1846题意:中文。mark:考虑n%(m+1)是否为0。代码:# include <stdio.h>int main (){ int T, n, m ; scanf ("%d", &T) ; while (T--) { scanf ("%d%d", &n, &m) ; puts (n%(m+1) ? "first" : "second") ; } re 阅读全文

posted @ 2012-01-06 23:27 Seraph2012 阅读(103) 评论(0) 推荐(0)

[恢]hdu 1069
摘要:2011-12-22 17:22:12地址:http://acm.hdu.edu.cn/showproblem.php?pid=1069题意:有n种立方体,长宽高分别是x[i], y[i], z[i],每种数量无限。可以随意旋转。把他们垒起来,要求上面的立方体底面长和宽一定要分别小于下面立方体顶面的长和宽。问最高能垒多高。mark:一开始没看到数量无限,以为是单个的。想了好久不会做,后来看别人的解释才知道。每个方块扩展成3个,分别穷举出3边各为高的情况,排序,然后dp。本质是LIS。还蛮简单的。但是wa了n次,快折腾死我了。排序的策略我选择的是先x和x比,然后y和y比。但是我忽略了有x1< 阅读全文

posted @ 2012-01-06 23:26 Seraph2012 阅读(206) 评论(0) 推荐(0)

[恢]hdu 1847
摘要:2011-12-23 03:58:02地址:http://acm.hdu.edu.cn/showproblem.php?pid=1847题意:中文。。。mark:是简单博弈。。但是不会博弈论表示鸭梨很大,好在题目数据不大,直接爆。代码:# include <stdio.h>int dp[1001] = {0, 1, 1, 0} ;int main (){ int i, j, n ; for (i = 4 ; i <= 1000 ; i++) for (j = 1 ; j <= i ; j<<=1) if (dp[i-j] == 0) dp[i] ... 阅读全文

posted @ 2012-01-06 23:26 Seraph2012 阅读(133) 评论(0) 推荐(0)

[恢]hdu 1087
摘要:2011-12-21 11:49:05地址:http://acm.hdu.edu.cn/showproblem.php?pid=1087题意:有n个point,每次只能往后跳,而且只能跳到分数比当前的大的point。score是路径上所有point的和。求最大score。mark:dp。效率是O(n^2)。dp[i] = max{dp[j] + a[i]), 0<=j<=i-1。代码:# include <stdio.h>int a[1010], dp[1010] ;int max(int a, int b){return a>b?a:b;}int main () 阅读全文

posted @ 2012-01-06 23:25 Seraph2012 阅读(217) 评论(0) 推荐(0)

[恢]hdu 2108
摘要:2011-12-21 11:00:01地址:http://acm.hdu.edu.cn/showproblem.php?pid=2108题意:中文,判断是否凸。代码:# include <stdio.h>typedef struct POINT{ int x, y ;}point ;point pt[1010] ;int n ;int direction (int x1, int y1, int x2, int y2){ return x1*y2 - x2*y1 ;}int test (){ int i ; pt[n] = pt[0], pt[n+1] = pt[1] ... 阅读全文

posted @ 2012-01-06 23:24 Seraph2012 阅读(181) 评论(0) 推荐(0)

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 24 下一页