随笔分类 -  HDOJ

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

发布一些HDOJ的做题情况以及代码。
[恢]hdu 2554
摘要:2011-12-29 13:51:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=2554题意:中文,有点绕但是能看懂,不多说了。mark:着实不会,看了网上的规律觉得好扯淡。n%4的余数是3或0的就是Y,否则是N。。。不知道怎么来的,打表也只能看到前12项,之后就非常慢了。代码(C编译):main(n){while(scanf("%d",&n),n){puts((n+1)&2?"N":"Y");}}打表的程序也贴一下吧:# include <stdio.h> 阅读全文

posted @ 2012-01-07 00:02 Seraph2012 阅读(226) 评论(0) 推荐(0)

[恢]hdu 2555
摘要:2011-12-29 22:32:38地址:http://acm.hdu.edu.cn/showproblem.php?pid=2555题意:中文。不多解释。mark:此题真是坑爹。数据里有多个矩形覆盖一个点的情况- -。。。如果有这种情况,就算前一个矩形的周长。。。另外,在矩形边上也算是包含在陷阱内。代码:# include <stdio.h># include <string.h># include <stdlib.h>typedef struct point{ int x, y ;}point ;point pt[20010] ;int a[110][ 阅读全文

posted @ 2012-01-07 00:02 Seraph2012 阅读(190) 评论(0) 推荐(0)

[恢]hdu 2560
摘要:2011-12-28 09:55:00地址:http://acm.hdu.edu.cn/showproblem.php?pid=2560题意:给n*m的0-1矩阵,问有多少个1。。。mark:这么水的题好爽!代码:# include <stdio.h>int main (){ int T, n, m, i, num, sum ; scanf ("%d", &T) ; while (T--) { scanf ("%d%d", &n, &m) ; sum = 0 ; for (i = 0 ; i < n*m ; i+ 阅读全文

posted @ 2012-01-07 00:00 Seraph2012 阅读(165) 评论(0) 推荐(0)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[恢]hdu 2095
摘要: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)

[恢]hdu 2138
摘要: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)

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

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