摘要:
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
阅读(118)
评论(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
阅读(133)
评论(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
阅读(129)
评论(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
阅读(198)
评论(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
阅读(231)
评论(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
阅读(147)
评论(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
阅读(226)
评论(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
阅读(215)
评论(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
阅读(141)
评论(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
阅读(135)
评论(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
阅读(175)
评论(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
阅读(212)
评论(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
阅读(142)
评论(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
阅读(190)
评论(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
阅读(105)
评论(0)
推荐(0)
摘要:
2011-12-27 00:24:46太不容易了。用了一周的时间才水掉50题。虽然有很多题都是看了解题报告的,但自豪的事情是,保证了每一题自己都踏踏实实地想清楚了。没有那种看了别人的公式就拿来ac的题目。 阅读全文
posted @ 2012-01-06 23:50
Seraph2012
阅读(76)
评论(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
阅读(137)
评论(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
阅读(193)
评论(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
阅读(164)
评论(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
阅读(151)
评论(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
阅读(136)
评论(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
阅读(235)
评论(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
阅读(137)
评论(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
阅读(175)
评论(0)
推荐(0)
摘要:
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
阅读(190)
评论(0)
推荐(0)
摘要:
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
阅读(144)
评论(0)
推荐(0)
摘要:
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
阅读(156)
评论(0)
推荐(0)
摘要:
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
阅读(158)
评论(0)
推荐(0)
摘要:
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
阅读(112)
评论(0)
推荐(0)
摘要:
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)
摘要:
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
阅读(150)
评论(0)
推荐(0)
摘要:
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)
摘要:
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)
摘要:
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
阅读(177)
评论(2)
推荐(0)
摘要:
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
阅读(156)
评论(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
阅读(203)
评论(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
阅读(139)
评论(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
阅读(266)
评论(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
阅读(154)
评论(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
阅读(139)
评论(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
阅读(275)
评论(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
阅读(133)
评论(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
阅读(141)
评论(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
阅读(160)
评论(0)
推荐(0)
摘要:
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
阅读(332)
评论(2)
推荐(0)
摘要:
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)
摘要:
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)
摘要:
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)
摘要:
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
阅读(158)
评论(0)
推荐(0)
摘要:
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
阅读(157)
评论(0)
推荐(0)
摘要:
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
阅读(124)
评论(0)
推荐(0)
摘要:
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
阅读(134)
评论(0)
推荐(0)
摘要:
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
阅读(156)
评论(0)
推荐(0)
摘要:
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)
摘要:
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
阅读(207)
评论(0)
推荐(0)
摘要:
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
阅读(137)
评论(0)
推荐(0)
摘要:
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
阅读(218)
评论(0)
推荐(0)
摘要:
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
阅读(183)
评论(0)
推荐(0)
摘要:
2011-12-21 11:19:32地址:http://acm.hdu.edu.cn/showproblem.php?pid=2151题意:中文。mark:递推。dp[i][j]表示第i分钟在第j颗树上的走法。dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1]。注意边界。代码:# include <stdio.h># include <string.h>int dp[110][110] ;int main (){ int n, p, m, t, i, j ; while (~scanf ("%d%d%d%d", & 阅读全文
posted @ 2012-01-06 23:24
Seraph2012
阅读(172)
评论(0)
推荐(0)
摘要:
2011-12-21 10:39:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=1391题意:给出坐标,输出坐标上的数字或No Number。代码:# include <stdio.h>int gao(int x, int y){ int ans ; if (x == y) return 2*x - (x&1) ; return gao(x, y+2) - 2 ;}int main (){ int T, x, y ; scanf ("%d", &T) ; while (T--) { sca... 阅读全文
posted @ 2012-01-06 23:23
Seraph2012
阅读(156)
评论(0)
推荐(0)
摘要:
2011-12-21 10:28:36地址:http://acm.hdu.edu.cn/showproblem.php?pid=1035题意:从最上方的第pos列进入,按照迷宫指示走,N向上,D向下,W向左,E向右,输出最终的结果(走出迷宫or循环)。代码:# include <stdio.h># include <string.h>char map[110][110] ;int dp[110][110] ;int n, m, loop ;int gao(int x, int y, int step){ if (x < 0 || x >= n || y &l 阅读全文
posted @ 2012-01-06 23:22
Seraph2012
阅读(159)
评论(0)
推荐(0)
摘要:
2011-12-21 09:46:27地址:http://acm.hdu.edu.cn/showproblem.php?pid=1785题意:中文。给点和原点连线与x轴夹角排序。代码:# include <stdio.h># include <stdlib.h>typedef struct point{ double x, y ;}point ;point pt[110] ;int cmp(const void *a, const void *b){ double x1 = ((point*)a)->x, y1 = ((point*)a)->y ; doub 阅读全文
posted @ 2012-01-06 23:22
Seraph2012
阅读(133)
评论(0)
推荐(0)
摘要:
2011-12-21 02:10:08地址:http://acm.hdu.edu.cn/showproblem.php?pid=1859题意:中文。每次更新就OK。代码:# include <stdio.h>int min(int a, int b){return a<b?a:b;}int max(int a, int b){return a>b?a:b;}int main (){ int x, y, l, r, t, d ; while (scanf ("%d%d", &x, &y) && (x||y)) { l = 阅读全文
posted @ 2012-01-06 23:21
Seraph2012
阅读(132)
评论(0)
推荐(0)
摘要:
2011-12-21 09:23:36地址:http://acm.hdu.edu.cn/showproblem.php?pid=1396题意:边长为n的大三角形含有边长大于等于1的小三角形多少个。mark:递推,分奇偶。考虑增加一列新的底边三角形时,头冲下的三角形和头冲上的三角形增加了多少个。代码:# include <stdio.h>int dp[510]= {0, 1} ;void init(){ int i ; for (i = 2; i <= 500 ; i++) { if (i & 1) dp[i] = dp[i-1] + (i*... 阅读全文
posted @ 2012-01-06 23:21
Seraph2012
阅读(295)
评论(0)
推荐(0)
摘要:
2011-12-21 02:04:56地址:http://acm.hdu.edu.cn/showproblem.php?pid=1716题意:中文。mark:dfs。代码:# include <stdio.h># include <algorithm>using namespace std ;int a[4], num[4], tab[10] ;int flag ;void dfs(int n){ int i ; if (n == 4) { if (flag == 0) flag = 1 ; else printf (" ") ; p... 阅读全文
posted @ 2012-01-06 23:20
Seraph2012
阅读(150)
评论(0)
推荐(0)
摘要:
2011-12-20 18:25:13HDOJ贰佰伍拾斩获。留念。最近做题很慢啊。而且各种犯2啊,而且各种不会啊。阻力好大啊。 阅读全文
posted @ 2012-01-06 23:19
Seraph2012
阅读(117)
评论(0)
推荐(0)
摘要:
2011-12-20 19:19:01地址:http://acm.hdu.edu.cn/showproblem.php?pid=1256题意:中文。mark:wa了一次,算横排长度的时候用h/6忘了+1。代码:# include <stdio.h># include <string.h>char g[110][110] ;void output (char ch, int h){ int a = (h-3) /2 , b = (h-2) /2 ; int c = 1 + h / 6 ; int i, j ; memset (g, ' ', sizeof 阅读全文
posted @ 2012-01-06 23:19
Seraph2012
阅读(142)
评论(0)
推荐(0)
摘要:
2011-12-20 18:17:43地址:http://acm.hdu.edu.cn/showproblem.php?pid=1194题意:已知两数和与两数差,求俩数。代码:# include <stdio.h>int main (){ int T, a, b ; scanf ("%d", &T) ; while (T--) { scanf ("%d%d", &a, &b) ; if (a < b || (a+b)%2 == 1) { puts ("impossible") ; contin 阅读全文
posted @ 2012-01-06 23:18
Seraph2012
阅读(163)
评论(0)
推荐(0)
摘要:
2011-12-20 18:23:34地址:http://acm.hdu.edu.cn/showproblem.php?pid=1197题意:输出所有符合条件的数字。条件就是4位数,用10进制表示的各个数码的和,等于16进制各数码的和,同时还等于12进制的。代码:# include <stdio.h>int test(int n, int b){ int sum = 0 ; while (n) { sum += n%b ; n/= b ; } return sum ;}int main (){ int i ; for (i ... 阅读全文
posted @ 2012-01-06 23:18
Seraph2012
阅读(209)
评论(0)
推荐(0)
摘要:
2011-12-20 17:54:28地址:http://acm.hdu.edu.cn/showproblem.php?pid=1143题意:用2*1的砖铺3*n,有多少种方法。mark:递推。dp[n] = 4*dp[n-2]-dp[n-4]代码:# include <stdio.h>int dp[35] = {1, 0, 3, 0} ;int main (){ int i, n ; for (i = 4 ; i<= 30 ; i+= 2) dp[i] = 4*dp[i-2] - dp[i-4] ; while (~scanf ("%d", &n 阅读全文
posted @ 2012-01-06 23:17
Seraph2012
阅读(155)
评论(0)
推荐(0)
摘要:
2011-12-20 17:20:41地址:http://acm.hdu.edu.cn/showproblem.php?pid=1098题意:给出k。求使得f(x)=5*x^13+13*x^5+k*a*x对任意x都为65的倍数的a的最小值。mark:65=13*5。要使f(x)是65的倍数,只需要f(x)是5和13的倍数即可。先来分析13的。若f(x)是13的倍数,有5*x^13+13*x^5+k*a*x % 13 == 0,其中13*x^5项显然不用考虑。则只需5*x^13 + k*a*x是13的倍数,即x*(5*x^12+k*a)是13的倍数。若x是13的倍数,不用考虑。若x不是13的倍数 阅读全文
posted @ 2012-01-06 23:17
Seraph2012
阅读(173)
评论(0)
推荐(0)
摘要:
2011-12-20 16:28:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=1039题意:判断一个字符串是否能被接受。要满足:1.含有元音字母。2.不存在3个连续的元音字母或辅音字母。 3.不存在连续两个相同的字母,除非是'ee'或'oo'。代码:# include <stdio.h># include <string.h>char str[1010] ;int isvowels (char ch){ if (ch == 'a' || ch == 'e' 阅读全文
posted @ 2012-01-06 23:16
Seraph2012
阅读(223)
评论(0)
推荐(0)
摘要:
2011-12-20 16:07:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=2062题意:求n个数集合的第m个子序列,按字典序排序,也就是说1 2 < 1 2 3 < 1 3。代码:# include <stdio.h># include <string.h>typedef long long ll ;ll n, m, dp[25] = {0, 1} ;int visited[25] ;int flag ;void init(){ int i ; for (i = 2 ; i <= 20 ; i++) 阅读全文
posted @ 2012-01-06 23:15
Seraph2012
阅读(191)
评论(0)
推荐(0)
摘要:
2011-12-20 16:13:50地址:http://acm.hdu.edu.cn/showproblem.php?pid=1037题意:输入一串数字,输出第一个小于168的数字。代码:# include <stdio.h>int main (){ int n ; while (~scanf ("%d", &n)) if (n < 168) break ; if (n < 168) printf ("CRASH %d\n", n) ; else printf ("NO CRASH\n") ; ret 阅读全文
posted @ 2012-01-06 23:15
Seraph2012
阅读(254)
评论(0)
推荐(0)
摘要:
2011-12-20 15:48:40地址:http://acm.hdu.edu.cn/showproblem.php?pid=2368题意:一个矩形的长宽分别为w、l的PIZZA是否能完全放在一个半径为r的桌子上。代码:# include <stdio.h>int main (){ int nCase = 1, l, w, r ; while (~scanf ("%d", &r) && r) { scanf ("%d%d", &w, &l) ; if (w*w+l*l<=4*r*r) print 阅读全文
posted @ 2012-01-06 23:14
Seraph2012
阅读(143)
评论(0)
推荐(0)
摘要:
2011-12-20 15:42:45地址:http://acm.hdu.edu.cn/showproblem.php?pid=2147题意:n*m的棋盘,一开始在右上角。每次只能走到左、下 或者左下。判胜败。mark:简单博弈。n、m同时为奇数则败。代码:# include <stdio.h>int main (){ int n, m ; while (~scanf ("%d%d", &n, &m)) { if (n == 0 && m == 0) break ; if (n&1 && m&1) 阅读全文
posted @ 2012-01-06 23:13
Seraph2012
阅读(150)
评论(0)
推荐(0)
摘要:
2011-12-20 15:33:41地址:http://acm.hdu.edu.cn/showproblem.php?pid=2212题意:找所有int范围内的数n满足他的各位数的阶乘和等于本身。mark:打表,只有4个。1、2、145、40585。代码:# include <stdio.h>int main (){ puts ("1\n2\n145\n40585") ; return 0 ;} 阅读全文
posted @ 2012-01-06 23:12
Seraph2012
阅读(163)
评论(0)
推荐(0)
摘要:
2011-12-20 15:23:47地址:http://acm.hdu.edu.cn/showproblem.php?pid=1407题意:中文。mark:TLE了几次,没想清楚循环上界。代码:# include <stdio.h># include <math.h>void gao(int num){ int x, y, z ; int lim1 = sqrt(num),lim2 ; for (x = 1 ; x <= lim1+1 ; x++) { lim2 = sqrt(num-x*x) ; for (y = x ; y <= lim... 阅读全文
posted @ 2012-01-06 23:10
Seraph2012
阅读(161)
评论(0)
推荐(0)
摘要:
2011-12-20 14:46:51地址:http://acm.hdu.edu.cn/showproblem.php?pid=1412题意:中文。代码:# include <stdio.h># include <stdlib.h>int a[10010], b[10010], c[20010] ;int cmp(const void *a, const void *b){ return *(int*)a - *(int*)b ;}int main (){ int n, m, cnt, i, j ; while (~scanf ("%d%d", &a 阅读全文
posted @ 2012-01-06 23:09
Seraph2012
阅读(117)
评论(0)
推荐(0)
摘要:
2011-12-20 15:08:24地址:http://acm.hdu.edu.cn/showproblem.php?pid=1337题意:和2053一样。代码:# include <stdio.h>int main (){ int T, n, i, ans ; int tab[] = {1,4,9,16,25,36,49,64,81,100} ; scanf ("%d", &T) ; while (T--) { scanf ("%d", &n) ; ans = 0 ; for (i = 0 ; i < 10 ; i+ 阅读全文
posted @ 2012-01-06 23:09
Seraph2012
阅读(116)
评论(0)
推荐(0)
摘要:
2011-12-20 14:08:27地址:http://acm.hdu.edu.cn/showproblem.php?pid=1017题意:给n和m,求满足0 < a < b < n 且(a^2+b^2 +m)/(ab)是整数的(a,b)有多少对。mark:格式比较蛋疼。代码:# include <stdio.h>int calc(int n, int m){ int i, j, rtn = 0 ; for (i = 1 ; i < n ; i++) for (j = i+1 ; j < n ; j++) if ((i*i+j*j+m) % (... 阅读全文
posted @ 2012-01-06 23:08
Seraph2012
阅读(183)
评论(0)
推荐(0)
摘要:
2011-12-20 13:33:58地址:http://acm.hdu.edu.cn/showproblem.php?pid=1249题意:中文。mark:前面假设有n-1个三角形,考虑一个新三角形每个边切已有边交点为2(n-1),新增小面为3*(2(n-1)-1),再加新增三个角,共新增小面6(n-1)块。所以dp[n] = dp[n-1]+6(n-1)。解得dp[n] = 3*n^2-3n+2。代码:# include <stdio.h>int main(){ int T, n ; scanf ("%d", &T) ; while (T--) { 阅读全文
posted @ 2012-01-06 23:07
Seraph2012
阅读(199)
评论(0)
推荐(0)
摘要:
2011-12-20 13:17:01地址:http://acm.hdu.edu.cn/showproblem.php?pid=1014题意:其实就是求两个数是否互素。是则为Good,否则为Bad。PE了2次。每组后面都有空行,数字10列,和字母之间是4个空格(开始写成5个)。代码:# include <stdio.h>int gcd(int a, int b){return a%b?gcd(b,a%b):b;}int main (){ char tab[2][15] = {"Bad Choice", "Good Choice"} ; int 阅读全文
posted @ 2012-01-06 23:06
Seraph2012
阅读(427)
评论(0)
推荐(0)
摘要:
2011-12-20 13:07:58地址:http://acm.hdu.edu.cn/showproblem.php?pid=1070题意:故事的主角喝牛奶每天喝200ml,不到200ml的牛奶直接扔掉。一罐牛奶最多只喝5天,超过5天扔掉。给n个牌子的牛奶价格和体积,问哪个最便宜。。。mark:wa了n次,没看到题目的一句话:If there are more than one cheapest brand, you should output the one which has the largest volume.另外有两个牌子都大于1000ml的情况,我一开始直接把大于1000的vol 阅读全文
posted @ 2012-01-06 23:04
Seraph2012
阅读(220)
评论(0)
推荐(0)
摘要:
2011-12-20 12:09:16地址:http://acm.hdu.edu.cn/showproblem.php?pid=2200题意:中文。mark:求公式。假如n个元素就是1~n。设较小的集合内最大的数字为i,则小集合可以有2^(i-1)种取法。较大的集合则有2^(n-1)-1种取法。把i从1到n累加起来,得公式(n-2)*2^(n-1)+1。代码:# include <stdio.h>int main (){ long long n ; while (~scanf ("%I64d", &n)) { printf ("%I64d\n& 阅读全文
posted @ 2012-01-06 23:00
Seraph2012
阅读(184)
评论(0)
推荐(0)
摘要:
2011-12-20 11:29:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1228题意:中文。代码:# include <stdio.h># include <string.h>int a, b, cnt ;char str[110] ;char words[11][11] ;void getword(){ int i, cc = 0 ; char cur_word[11] ; cnt = 0 ; for (i = 0 ; str[i] ; i++) { if (str[i] == ' '... 阅读全文
posted @ 2012-01-06 22:59
Seraph2012
阅读(140)
评论(0)
推荐(0)
摘要:
2011-12-20 11:11:18地址:http://acm.hdu.edu.cn/showproblem.php?pid=2036题意:中文。mark:求凸多边形面积。计算几何。代码:# include <stdio.h>typedef struct point{ int x, y ;}point ;point a[110] ;double area(point p, point q){ return p.x*q.y - p.y*q.x ;}int main (){ int i, n ; double sum ; while (~scanf ("%d", 阅读全文
posted @ 2012-01-06 22:58
Seraph2012
阅读(159)
评论(0)
推荐(0)
摘要:
2011-12-20 08:41:25地址:http://acm.hdu.edu.cn/showproblem.php?pid=1425题意:中文。mark:PE1次。排序。没有m>n的情况。代码:# include <stdio.h># include <stdlib.h>int a[1000010] ;int cmp(const void *a, const void *b){ return *(int*)b - *(int*)a ;}int main (){ int n, m, i; while (~scanf ("%d%d", & 阅读全文
posted @ 2012-01-06 22:57
Seraph2012
阅读(153)
评论(0)
推荐(0)
摘要:
2011-12-20 08:09:43地址:http://acm.hdu.edu.cn/showproblem.php?pid=2526题意:中文。直接模拟。代码:# include <stdio.h>int dp[1010][210] ;int flag[200], m ;char str[210] ;int get(int a, int b, int c){ return flag[a*100+b*10+c] ;}void output(){ int i, j, len = 0 ; for (i = 0 ; str[i] ;i++) { dp[0][... 阅读全文
posted @ 2012-01-06 22:56
Seraph2012
阅读(139)
评论(0)
推荐(0)
摘要:
2011-12-20 08:35:28地址:http://acm.hdu.edu.cn/showproblem.php?pid=1003题意:找n个数里连续的一串和最大。mark:dp。wa了2次。第一次没考虑负数。第二次少考虑-1 2这种情况。代码:# include <stdio.h>int n, a[100010] ;int spos, epos, max_ans ;int gao(){ int i, s = 0, ans = a[0] ; spos = epos = 0 ; max_ans = a[0] ; for (i = 1 ; i < n ; i++) ... 阅读全文
posted @ 2012-01-06 22:56
Seraph2012
阅读(127)
评论(0)
推荐(0)
摘要:
2011-12-20 07:55:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=1408题意:中文。mark:输入其实是实数。。。题目没说清楚。OLE了一次,wa了好几次,都是精度惹的祸。过了以下测试数据应该就没大问题了。intput10 111 11 0.11.1 0.1output13151315代码:# include <stdio.h>int main (){ double vul, d ; int i, ans ; while (~scanf ("%lf%lf", &vul, &d)) { 阅读全文
posted @ 2012-01-06 22:55
Seraph2012
阅读(164)
评论(0)
推荐(0)
摘要:
2011-12-20 07:12:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=2522题意:中文。。mark:模拟除法运算,注意判循环节,注意负数。代码:# include <stdio.h>int flag[1000010] ;void output(int a, int b){ if (a == 1) return ; if (flag[a]) return ; flag[a] = 1 ; printf ("%d", a/b) ; if (a % b != 0 && a%b != 1) out 阅读全文
posted @ 2012-01-06 22:54
Seraph2012
阅读(209)
评论(0)
推荐(0)
摘要:
2011-12-20 06:54:39地址:http://acm.hdu.edu.cn/showproblem.php?pid=2523题意:中文。mark:运用到桶排序。代码:# include <stdio.h>int x[2010], flag[2010] ;int cnt ;int abs(int n){return n<0?-n:n;}int main (){ int T, n, k, i, j ; scanf ("%d", &T) ; while (T--) { scanf ("%d%d", &n, & 阅读全文
posted @ 2012-01-06 22:52
Seraph2012
阅读(188)
评论(0)
推荐(0)
摘要:
2011-12-20 06:44:37地址:http://acm.hdu.edu.cn/showproblem.php?pid=2521题意:中文。mark:反素数直接for for暴力求,约莫计算不到10w次。查询可用ST算法,但这题没必要,直接扫就好了。代码:# include <stdio.h>int factor[5010] ;void init(){ int i, j ; for (i = 2 ; i <= 5000 ; i++) { for (j = i ; j <= 5000 ; j+= i) factor[j] ++ ; ... 阅读全文
posted @ 2012-01-06 22:51
Seraph2012
阅读(171)
评论(0)
推荐(0)
摘要:
2011-12-20 06:30:12地址:http://acm.hdu.edu.cn/showproblem.php?pid=2519题意:中文。其实就是算组合数。mark:即使是long long,算阶乘也只能算到20!,因此用杨辉三角比较简单。代码:# include <stdio.h>int c[31][31] ;void init(){ int i, j ; c[0][0] = 1 ; for (i = 1 ; i <= 30 ; i++) { c[i][0] = 1 ; for (j = 1 ; j <= i ; j++) ... 阅读全文
posted @ 2012-01-06 22:50
Seraph2012
阅读(167)
评论(0)
推荐(0)
摘要:
2011-12-20 06:25:07地址:http://acm.hdu.edu.cn/showproblem.php?pid=1701题意:求一个最小的n,满足n*p%和n%q%中间夹着一个整数。mark:题意真是太诡异了。看了discuss才知道啥意思。最大不会超过10000, 直接搜过。代码。# include <stdio.h>int gcd(int a, int b){return a%b==0?b:gcd(b,a%b) ;}int main (){ int T, i, p, q ; double pp, qq ; scanf ("%d", & 阅读全文
posted @ 2012-01-06 22:49
Seraph2012
阅读(182)
评论(0)
推荐(0)
摘要:
2011-12-20 06:11:14地址:http://acm.hdu.edu.cn/showproblem.php?pid=2537题意:中文,模拟。代码:# include <stdio.h>int gao(int n){ char ch ; int r = 7, y = 7 ; while (n--) { scanf ("%c", &ch) ; if (ch == 'R') r-- ; if (ch == 'Y') y-- ; if (ch == 'B') return r==0 ; if (... 阅读全文
posted @ 2012-01-06 22:48
Seraph2012
阅读(190)
评论(0)
推荐(0)
摘要:
2011-12-20 05:55:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=1868题意:问n可以表示成连续数字和有多少种。mark:和2058如出一辙。TLE了2次,忘记改成long long,算sqrt的时候有个8倍会溢出。代码:# include <stdio.h># include <math.h>typedef long long ll ;ll calc (ll b){ int ans = 0 ; ll n, p ; for (n = ((ll)sqrt(8*b+1)-1) / 2 ; n > 1 ; 阅读全文
posted @ 2012-01-06 22:47
Seraph2012
阅读(151)
评论(0)
推荐(0)
摘要:
2011-12-20 05:34:39地址:http://acm.hdu.edu.cn/showproblem.php?pid=2106题意:n个不同进制的数求和。代码:# include <stdio.h>int base(int a, int b){ if (a == 0) return 0 ; return b * base(a/10, b) + a%10 ;}int main (){ int n, sum, a, b ; while (~scanf ("%d", &n)) { sum = 0 ; while (n--) ... 阅读全文
posted @ 2012-01-06 22:46
Seraph2012
阅读(184)
评论(0)
推荐(0)
摘要:
2011-12-20 05:26:53地址:http://acm.hdu.edu.cn/showproblem.php?pid=1405题意:分解素因子。mark:PE2次。每行最后有一个空格。太无聊了- -。代码:# include <stdio.h>void output(int n){ int i, cnt ; for (i = 2 ; n != 1 ; i++) { if (n%i==0) { cnt = 0 ; while (n%i==0){cnt++; n/=i;} pr... 阅读全文
posted @ 2012-01-06 22:45
Seraph2012
阅读(212)
评论(2)
推荐(1)

浙公网安备 33010602011771号