上一页 1 ··· 19 20 21 22 23 24 25 26 27 ··· 51 下一页
摘要: 2011-12-25 10:20:50地址:http://acm.hdu.edu.cn/showproblem.php?pid=1215题意:问n的真因子和。mark:这题可以说是不会,题目数据量是50w,我直接搜到sqrt(n),复杂度应该是O(n*sqrt(n)),大约是700*50w = 3.5亿。若不是数据水,理应TLE的。感觉正统的做法是分解素因子后组合。素因子最多不超过log(n)个,约20个,然后组合。感觉还是有可能TLE。代码:# include <stdio.h># include <math.h>int calc(int n){ int sum = 阅读全文
posted @ 2012-01-06 23:39 Seraph2012 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 2011-12-25 09:54:46地址:http://acm.hdu.edu.cn/showproblem.php?pid=1242题意:angel被困在迷宫里,他的朋友们去救。n*m的迷宫,'.'代表路,'#'代表墙,'x'代表守卫,'r'代表朋友,'a'代表ANGEL。求最少时间。mark:BFS。注意有多个“朋友”,所以从a开始搜。代码:# include <stdio.h># include <string.h>int n, m, sx, sy ;char graph[210][ 阅读全文
posted @ 2012-01-06 23:38 Seraph2012 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 2011-12-25 09:14:55地址:http://acm.hdu.edu.cn/showproblem.php?pid=1372题意:8*8的棋盘,给两个点,问Knight最少走几步能从一个点走到另一个点。mark:直接bfs即可。代码:# include <stdio.h># include <string.h># define SIZE 8int graph[70][70] ;int visited[10][10] ;int q[1000] ;int min(int a, int b){return a<b?a:b;}int abs(int n){re 阅读全文
posted @ 2012-01-06 23:37 Seraph2012 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 2011-12-24 21:46:41地址:http://acm.hdu.edu.cn/showproblem.php?pid=1896题意:n个石头,每个在位置p,一个属性d。从最左边开始往右走,遇到一个石头,如果是第奇数次遇到,就把他往前仍d米,偶数次遇到就越过。问最后最远的石头距离起点多少米。mark:10w个石头,如果不扔 第一次会越过5w个,还剩5w个。依次分析,最后其实总操作不到20w。用优先队列,O(nlgn)。不会用STL,用手写堆实现了一个优先队列,居然1A。代码:# include <stdio.h>typedef struct node{ int p, d ; 阅读全文
posted @ 2012-01-06 23:36 Seraph2012 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(149) 评论(0) 推荐(0) 编辑
上一页 1 ··· 19 20 21 22 23 24 25 26 27 ··· 51 下一页