上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 51 下一页
摘要: 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 阅读(98) 评论(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 阅读(125) 评论(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 阅读(183) 评论(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 阅读(152) 评论(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 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 10:54:08地址:http://acm.hdu.edu.cn/showproblem.php?pid=1010题意:从S走到D是否存在一条路径(走过的方格不能再走)使得正好用T的时间走完。mark:dfs加奇偶剪枝。代码:# include <stdio.h># include <string.h>int sx, sy, ex, ey ;int n, m, T;char graph[110][110] ;int visited[110][110] ;int dfs (int x, int y, int t){ int i, xx, yy ; i 阅读全文
posted @ 2012-01-06 23:47 Seraph2012 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 11:43:27地址:http://acm.hdu.edu.cn/showproblem.php?pid=1404题意:一个字符串,每次可以把其中任何一个非0数码变成比它小的数码,或把一个0数码以及其右边的所有数码删掉。最后操作的人获胜,问先手是否能必胜。mark:因为数据量实在很小,所以直接爆搜就好了。但是要用上字符串哈希、记忆化搜索,否则还是会TLE的。跑了400+ms。代码:# include <stdio.h># include <string.h>int dp[2000010] ;int tab[] = {0, 0, 10, 110, 1 阅读全文
posted @ 2012-01-06 23:47 Seraph2012 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 09:33:25地址:http://acm.hdu.edu.cn/showproblem.php?pid=1241题意:给map,求'@'的联通片数。mark:注意相邻是指周围8格区域内。循环内套bfs或dfs都可以。代码:# include <stdio.h>char graph[110][110] ;int n, m ;void dfs (int x, int y){ int i, xx, yy ; int tab[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, ... 阅读全文
posted @ 2012-01-06 23:46 Seraph2012 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 2011-12-26 09:44:26地址:http://acm.hdu.edu.cn/showproblem.php?pid=1056题意:问1/2+1/3+1/4...+1/n不超过输入的最大n是多少。mark:1wa,注意0.5算1。代码:# include <stdio.h># include <math.h>double tab[300] ;int main (){ int i ; double num ; for (i = 2 ; i <= 280 ; i++) tab[i] = tab[i-1] + 1.0/i ; while (~scanf... 阅读全文
posted @ 2012-01-06 23:46 Seraph2012 阅读(164) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 51 下一页