随笔分类 -  HDOJ

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

发布一些HDOJ的做题情况以及代码。
[恢]hdu 1032
摘要: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 阅读(162) 评论(0) 推荐(0)

[恢]hdu 1730
摘要: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 阅读(150) 评论(0) 推荐(0)

[恢]hdu 1010
摘要: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 阅读(132) 评论(0) 推荐(0)

[恢]hdu 1404
摘要: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 阅读(234) 评论(0) 推荐(0)

[恢]hdu 1241
摘要: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 阅读(135) 评论(0) 推荐(0)

[恢]hdu 1056
摘要: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 阅读(172) 评论(0) 推荐(0)

[恢]hdu 1302
摘要:2011-12-26 09:07:10地址:http://acm.hdu.edu.cn/showproblem.php?pid=1302题意:有个蜗牛爬墙。墙高H。一开始每天白天能爬U,晚上滑下来D。之后因为疲劳,每天能爬的高度都比前一天减少U*F%。问何时能离开墙(爬过或跌下来)。mark:直接模拟。代码:# include <stdio.h>int h, u, d, f ;int gao(){ double a = 0, b = u, c = 1.0*f/100.0 * u ; int days = 1 ; while (1) { // printf (... 阅读全文

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

[恢]hdu 1312
摘要:2011-12-26 09:19:37地址:http://acm.hdu.edu.cn/showproblem.php?pid=1312题意:在铺满红砖和黑砖的房间里,一个人每次只能移动到黑砖,问有多少个砖块是可达的。mark:bfs和dfs都可以。。。数据又很小,才20。代码:# include <stdio.h># include <string.h>int ans, n, m ;char graph[30][30] ;int visited[30][30] ;void dfs(int x, int y){ int xx, yy, i; int tab[4][2] 阅读全文

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

[恢]hdu 1250
摘要:2011-12-26 00:33:25地址:http://acm.hdu.edu.cn/showproblem.php?pid=1250题意:F[1] = F[2] = F[3] = F[4] = 1。F[n] = F[n-1]+F[n-2]+F[n-3]+F[n-4]。输入n,求F[n]。大数运算。代码:# include <stdio.h>int a[6][2100] ;int buff[2100] ;void add(int x[], int y[]){ int i, *p, *q, cc = 0 ; if (x[0] < y[0]) p = x, q = y ; e. 阅读全文

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

[恢]hdu 1276
摘要:2011-12-25 19:32:54地址:http://acm.hdu.edu.cn/showproblem.php?pid=1276题意:中文。mark:链表。用的静态的。代码:# include <stdio.h># include <memory.h>int node[5010][2] ;void init (int n){ int i ; for (i = 0 ; i <= n; i++) { node[i][0] = i ; node[i][1] = i+1 ; } node[0][0] = n ; node[n][1... 阅读全文

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

[恢]hdu 1181
摘要:2011-12-26 00:07:58地址:http://acm.hdu.edu.cn/showproblem.php?pid=1181题意:中文,水。mark:bfs练习。代码:# include <stdio.h># include <string.h>char str[200] ;int graph[30][30] ;int visited[30] ;int q[30] ;int gao(){ int i, ch ; int front = 0, rear = 0 ; q[rear++] = 1 ; while (front != rear) { ... 阅读全文

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

[恢]hdu 1237
摘要:2011-12-25 15:48:22地址:http://acm.hdu.edu.cn/showproblem.php?pid=1237题意:中文。mark:用递归替代栈。1WA。开始没考虑到1 - 2 + 2的情况。把2+2先算了。。。代码:# include <stdio.h># include <string.h>char str[1010] ;double num[1010] ;char op[1010] ;int cnt ;void getWord (){ double buff = 0 ; int i, flag = 0 ; for (i = 0 ; str 阅读全文

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

[恢]hdu 2116
摘要:2011-12-25 18:26:30地址:http://acm.hdu.edu.cn/showproblem.php?pid=2116题意:输入K和两个K位带符号二进制数,判断两个数的和有没有溢出。mark:不要用两个数加起来判断溢出,要用max减去一个数,否则会出bug。另外不知道为啥要写小于号才能过,小于等于号不行。代码:# include <stdio.h>long long a, b ;int k ;int test (){ long long max, min ; if (k == 64) max = 0x7fffffffffffffffLL ; else max... 阅读全文

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

[恢]hdu 2206
摘要:2011-12-25 11:39:37地址:http://acm.hdu.edu.cn/showproblem.php?pid=2206题意:判断一个字符串是否是合法IP。mark:没啥好说的,写就好了。代码:# include <stdio.h>char str[110] ;int test (char str[]){ int i, flag = 0, buff, cnt = 0 ; for (i = 0 ; str[i] ; i++) { if (str[i] != '.' && (str[i] > '9' || str[i 阅读全文

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

[恢]hdu 1203
摘要:2011-12-25 11:17:07地址:http://acm.hdu.edu.cn/showproblem.php?pid=1203题意:中文。。。mark:标准01背包。概率正着不好算,算拿不到的概率就好了。代码:# include <stdio.h>double dp[10010] ;int n, m ;double min(double a, double b){return a<b?a:b;}int main (){ int i, j, cost ; double prob ; while (~scanf ("%d%d", &m, &a 阅读全文

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

[恢]hdu 1280
摘要:2011-12-25 11:25:29地址:http://acm.hdu.edu.cn/showproblem.php?pid=1280题意:输入n个数,输出两两和的前m个。mark:桶排序的经典应用。代码:# include <stdio.h># include <string.h>int tab[10010] ;int a[3010] ;void output (int m){ int i, cnt = 0, flag = 0 ; for (i = 10000 ; i >= 0 ; i --) { while (tab[i]) { ... 阅读全文

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

[恢]hdu 1215
摘要: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 阅读(153) 评论(0) 推荐(0)

[恢]hdu 1242
摘要: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 阅读(203) 评论(0) 推荐(0)

[恢]hdu 1372
摘要: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 阅读(138) 评论(0) 推荐(0)

[恢]hdu 1896
摘要: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 阅读(265) 评论(0) 推荐(0)

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