摘要: 2011-12-28 09:47:29地址:http://acm.hdu.edu.cn/showproblem.php?pid=1907题意:n堆石子,每次取走其中一堆的任意颗,最后一个取的人败,求判局势。mark:anti-nim,开始以为很简单,其实很难分析,搞了好久。具体可以参见2009年国家集训队贾志豪的论文。这里先给出anti-nim的结论:先手必胜当且仅当:1)sg值为0且不存在一堆sg值大于1;2)sg不为0且存在至少一堆sg值大于1。代码:# include <stdio.h>int main (){ int T, n, num, sg, flag ; scanf 阅读全文
posted @ 2012-01-06 23:59 Seraph2012 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 16:18:37地址:http://acm.hdu.edu.cn/showproblem.php?pid=2553题意:求n皇后放置的种类数。mark:因为n才10,所以直接dfs。代码:# include <stdio.h>int n, dp[11] = {0, 1} ;int ans, num[11] ;int col[11], diag[30], indiag[100] ;void dfs(int pos){ int i, j ; if (pos == n) { ans ++ ; return ; } for... 阅读全文
posted @ 2012-01-06 23:58 Seraph2012 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 16:40:47地址:http://acm.hdu.edu.cn/showproblem.php?pid=2082题意:中文。mark:YY了一个dp。dp[i][j]表示前i个字符组成价值为j的种类数,有dp[i][j] = dp[i-1][j-k*i],k∈[0,a[i]]。a[i]是第i个字符的最大个数。最后把dp[26]的所有值(0除外)加起来就ok了。代码:# include <stdio.h># include <string.h>int dp[30][60] ;int a[30] ;int main (){ int T, i, j, 阅读全文
posted @ 2012-01-06 23:58 Seraph2012 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 15:46:58地址:http://acm.hdu.edu.cn/showproblem.php?pid=1326题意:n个高矮不等的堆。每次可以从一个堆拿一块移动到另一堆。问最少移动多少次能使他们全都相等。mark:好经典的题目,不记得在哪儿看到过不只1次了。每个和平均数的差加起来除以二。代码:# include <stdio.h>int num[60] ;int n ;int abs(int n){return n<0?-n:n;}int main (){ int i, sum ,ans, nCase = 1 ; while (~scanf (&qu 阅读全文
posted @ 2012-01-06 23:57 Seraph2012 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 16:05:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1329题意:有n个棍子,依序从1开始放小球,两个相邻的球编号和必须是完全平方数。求最后一个能放下的序号。mark:最多才1300,直接模拟。代码:# include <stdio.h># include <string.h># include <math.h>int n ;int dp[55] ;int issquare(int a){ int b = sqrt(1.0*a) ; return b*b == a ;}int gao 阅读全文
posted @ 2012-01-06 23:57 Seraph2012 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 15:02:12地址:http://acm.hdu.edu.cn/showproblem.php?pid=1267题意:中文。刚开始没看懂,注意“总”字。代码:# include <stdio.h>long long dp[21][21] ;int main (){ int i, j, m, n ; for (i = 0 ; i <= 20 ; i++) dp[0][i] = 1 ; for (i = 1 ; i <= 20 ; i++) for (j = i ; j <= 20 ; j++) dp[i]... 阅读全文
posted @ 2012-01-06 23:56 Seraph2012 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 15:16:26地址:http://acm.hdu.edu.cn/showproblem.php?pid=1287题意:这题的题意很让人莫名。其实是说存在一个大写字母x,然后让原文(都是大写字母)和x做xor后得到密文。现在给密文求原文。因为x不知道,所以枚举x。判断方法是判断是否解密出来的原文都在'A'-'Z'范围内。代码:# include <stdio.h>int num[10010] ;int n ;int test (int x){ int i ; for (i = 0 ; i < n ; i++) if ((n 阅读全文
posted @ 2012-01-06 23:56 Seraph2012 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 14:25:01地址:http://acm.hdu.edu.cn/showproblem.php?pid=1220题意:一个n*n*n的立方体,被切割成1*1*1的小块。两两配对,问两块公共点不超过2的对数。mark:先算出总对数,减去共面的对数。顶点8个,每个共面3对,棱12条,每条有n-2个方块,每个方块共面4对,非顶点非楞的面上小方块,每个共面5对,一共6个面,每个面有(n-2)^2个这样的小方块。剩下的内部小方块每个共面6对。最后总共面数要除以2,因为每对算了2次。代码:# include <stdio.h>int calc (int n){ int 阅读全文
posted @ 2012-01-06 23:55 Seraph2012 阅读(200) 评论(1) 推荐(0) 编辑
摘要: 2011-12-27 13:44:49地址:http://acm.hdu.edu.cn/showproblem.php?pid=1862题意:中文,排序。代码:# include <stdio.h># include <stdlib.h># include <string.h>typedef struct student{ char num[7] ; char name[9] ; int grade ;}student ;student stu[100010] ;int cmp1(const void *a, const void *b){ student 阅读全文
posted @ 2012-01-06 23:54 Seraph2012 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 14:03:37地址:http://acm.hdu.edu.cn/showproblem.php?pid=1165题意:模拟图中给出的函数计算。mark:直接记忆化肯定会爆栈。写几行就发现,m=0,1,2的规律了。m=3的时候直接爆。代码:# include <stdio.h>int mem[25] = {5, 13} ;int A(int m, int n){ if (m == 0) return n+1 ; if (m == 1) return n+2 ; if (m == 2) return n*2+3 ; if (mem[n] != 0) ... 阅读全文
posted @ 2012-01-06 23:54 Seraph2012 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 13:30:48地址:http://acm.hdu.edu.cn/showproblem.php?pid=1015题意:在给定字符集中选5个字符(v,w,x,y,z)使得满足v - w^2 + x^3 - y^4 + z^5 = target。输出字典序最大的一个。mark:dfs。1WA。一开始以为是字符集中序数最大的(被case2误导了)。先给字符串排一下序就好了。代码:# include <stdio.h># include <string.h># include <stdlib.h>char ans[10] ;int visit 阅读全文
posted @ 2012-01-06 23:53 Seraph2012 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 12:28:09地址:http://acm.hdu.edu.cn/showproblem.php?pid=1027题意:求n个数的第m个排列。mark:最简单快捷有效的方法当然是用next_permutation,但是为了锻炼代码能力还是自己写一下。用flag标记已经选过不能选的数字,find用来查找最小的第num个数字。因为m最多只有10000, 所以当n大于8的时候不需要考虑,直接输出最小的数,递归处理。代码:# include <stdio.h># include <string.h>int flag[1010] ;int label ;in 阅读全文
posted @ 2012-01-06 23:52 Seraph2012 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 12:56:41地址:http://acm.hdu.edu.cn/showproblem.php?pid=1016题意:输入n,输出满足条件的1开头的n个数的排列。条件是相邻两个元素和为素数,而且首尾和为素数。mark:直接dfs。其实非1奇数的情况不存在解。因为总有2个加起来是偶数。代码:# include <stdio.h>int num[25] = {1} ;int visited[25] = {0, 1} ;int n ;int isprime (int n){ // 0 1 2 3 4 5 6 7 8 9 in... 阅读全文
posted @ 2012-01-06 23:52 Seraph2012 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 05:21:34地址:http://acm.hdu.edu.cn/showproblem.php?pid=1029题意:给n(奇数)个数字,求哪个数出现了至少(n+1)/2次。mark:利用hash。代码:# include <stdio.h># include <string.h># define MOD 999997int tab[MOD][2] ;int ans, max_num ;int hash(int num){ int idx = num % MOD ; while (tab[idx][1] != num && tab 阅读全文
posted @ 2012-01-06 23:51 Seraph2012 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 05:25:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=2095题意:输入n(1000000)个数字,其中只有一个出现了奇数次。问是哪个。mark:这题入选了M67大牛所说的最巧妙的算法题之一。方法是XOR起来。因为a^b^a=b。代码:# include <stdio.h>int main (){ int n, num, ans ; while (~scanf ("%d", &n) && n) { ans = 0 ; while (n--) { ... 阅读全文
posted @ 2012-01-06 23:51 Seraph2012 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 00:24:46太不容易了。用了一周的时间才水掉50题。虽然有很多题都是看了解题报告的,但自豪的事情是,保证了每一题自己都踏踏实实地想清楚了。没有那种看了别人的公式就拿来ac的题目。 阅读全文
posted @ 2012-01-06 23:50 Seraph2012 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 23:30:29地址:http://acm.hdu.edu.cn/showproblem.php?pid=2138题意:输入n个数,问有几个是素数。mark:它没说具体规模,开始觉得很麻烦。其实只要到sqrt(num)判断素数性质就好了。。。正规的做法是miller-rabin检测吧。代码:# include <stdio.h># include <math.h>int isprime(int n){ int i, limit = sqrt(1.0*n) ; for (i = 2 ; i <= limit ; i++) if (n%i==0) 阅读全文
posted @ 2012-01-06 23:49 Seraph2012 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 2011-12-27 00:16:34地址:http://acm.hdu.edu.cn/showproblem.php?pid=1030题意:问图里两个数字之间最少需要多少步。mark:注意小数在前大数在后,先算出行列,然后分奇偶。代码:# include <stdio.h># include <math.h>int min(int a, int b){return a<b?a:b;}int max(int a, int b){return a>b?a:b;}int row(int n){ int r = sqrt(1.0*n) ; if (r*r == n 阅读全文
posted @ 2012-01-06 23:49 Seraph2012 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 12:12:51地址:http://acm.hdu.edu.cn/showproblem.php?pid=1032题意:一个数,如果是奇数,变成3倍+1, 如果是偶数,变成原来的一半, 直到1为止,次数叫做循环长度。给一个范围,问范围内最大循环长度。mark:100w,打表记忆化搜。询问次数不多,直接O(n)扫过就好,如果还严格些可以用RMQ。代码:# include <stdio.h>int dp[1000010] = {0, 1, 2} ;int dfs (long long num){ long long next = ((num&1) ? (n 阅读全文
posted @ 2012-01-06 23:48 Seraph2012 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 23:03:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=1730题意:中文。mark:sg,nim博弈。每行考虑两个棋子之间的距离。每次减小距离。增大距离是没有意义的,因为对手下一步可以执行同样的策略来减小。代码:# include <stdio.h>int abs(int n){return n<0?-n:n;}int main (){ int i, n, m, sg, a, b ; while (~scanf ("%d%d", &n, &m)) { sg = 0 ; 阅读全文
posted @ 2012-01-06 23:48 Seraph2012 阅读(145) 评论(0) 推荐(0) 编辑