随笔分类 -  HDOJ

上一页 1 2 3 4 5 6 7 ··· 24 下一页

发布一些HDOJ的做题情况以及代码。
hdu 1045
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1045题意:给定一个最大4*4的方形地图,里面有墙(X)和空地(.)。在每个空地上可以放大炮,但两个大炮如果在同一行或同一列并且之间没有墙阻隔的话,会互相攻击,所以不能同时存在。问最多能放多少个大炮。mark:数据小,直接dfs就可以了。1WA,把保存状态的数组开成了全局的- -。据说还可以二分匹配过。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 char g[4][4] ; 6 int vis[4][4] ; 7 阅读全文

posted @ 2012-05-23 06:14 Seraph2012 阅读(835) 评论(0) 推荐(0)

hdu 2390
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2390题意:输入n个运动会项目的举办天和起止时间,不能同时看两场,问最多能看多少场。mark:经典贪心,注意每组输出后面都有一个空行。代码: 1 # include <stdio.h> 2 # include <stdlib.h> 3 4 5 typedef struct NODE{ 6 int s, t ; 7 }NODE ; 8 9 10 NODE sche[50010] ;11 12 13 int cmp(const void *a, const void *b)14 {1 阅读全文

posted @ 2012-05-23 05:44 Seraph2012 阅读(155) 评论(0) 推荐(0)

hdu 2191
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2191题意:中文。512地震默哀。mark:dp。多重背包。先做了1171再做这题就很容易了。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 int dp[110] ; 6 7 8 int main () 9 {10 int T, ans, n, m ;11 int p, h, c, i, j ;12 scanf ("%d", &T) ;13 while (T--)14 {15 ... 阅读全文

posted @ 2012-05-23 05:33 Seraph2012 阅读(799) 评论(0) 推荐(0)

hdu 1176
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1176题意:中文。mark:dp即可。。。类似数塔。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 int dp[100010][11] ; 6 int n , INF = 0x0f0f0f0f ; 7 8 9 int main ()10 {11 int i, j, k, buff, x, t ;12 int max_t, ans ;13 while (~scanf("%d",&n)& 阅读全文

posted @ 2012-05-23 05:22 Seraph2012 阅读(215) 评论(0) 推荐(0)

hdu 1171
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1171题意:有n样物品,每样物品价值是v,件数是m。尽量把这些物品分成两堆使得两边总价值最接近。输出价值。mark:水dp,或者用母函数搞。wa了3次,trick在于结束标记是负数,而非-1。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 int dp[250010] ; 6 7 8 int main () 9 {10 int i, j, k, sum ;11 int n, m, v ;12 while (~s... 阅读全文

posted @ 2012-05-23 05:11 Seraph2012 阅读(363) 评论(0) 推荐(0)

hdu 2700
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2700题意:一个字符串如果有偶数个1,就是o,有奇数个1就是e。给出缺了最后一位的字符串和它的属性,求补足最后一位的字符串。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 char str[110] ; 6 7 int main () 8 { 9 int i, cnt, len ;10 11 12 while (gets (str))13 {14 if (strcmp(str, "... 阅读全文

posted @ 2012-05-23 04:50 Seraph2012 阅读(278) 评论(0) 推荐(0)

hdu 2707
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2707题意:在一篇文章中,每一段连续的空格代表一个0或一个1。偶数个代表1,奇数个则为0。把所有空格连起来得到一串0-1组成的二进制,再进行解密。每5个0-1二进制字符对应1个字母,末尾不足5个补零。二进制对应的十进制中,0代表空格,1代表A,2代表B……26代表Z,之后27到31分别代表',-.?。按要求解密文章。mark:暴力搞就好,题目说保证空格不出现在每行的行头和行尾,就简单多了。装逼没有好下场,1wa就wa在不想用memset,结果i+j>=cnt写成了i+j>cnt。。。 阅读全文

posted @ 2012-05-21 16:56 Seraph2012 阅读(307) 评论(0) 推荐(0)

hdu 2703
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2703题意:有n条通道首尾相连,每个通道有一个容量p和一个通过时间sec,表示最多一次能一起进p个人,需要sec的时间通过。现在有m个人在第一条通道的开始处,他们按照策略通过n条通道。策略有2点要遵守,1是每个通道同一时间只能进一组人,2是只要通道为空并且通道口有人,通道口的人必须立刻进入通道(显然这不一定是最佳策略)。现在就按要求模拟题意,最后问m个人都通过的总用时。mark:一开始觉得是个纯阅读题,再后来发现写起来有的地方也挺难想的。数据规模较小,直接暴搞(总用时最大才780s)。代码: 1 # i 阅读全文

posted @ 2012-05-04 13:32 Seraph2012 阅读(286) 评论(0) 推荐(0)

hdu 2572
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2572题意:中文。mark:直接暴搞。1wa,注意要取字母序最小的,长度要先判断。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 char ans[110] ; 6 char s1[110], s2[110], s3[110] ; 7 char ss[110] ; 8 9 10 int find(char s[], char p[])11 {12 int i, j, len1 = strlen(s), len2 = s 阅读全文

posted @ 2012-05-03 05:41 Seraph2012 阅读(260) 评论(0) 推荐(0)

hdu 1804
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1804题意:要把输入的英文字符串转化成复数的形式。mark:规则就是那4条。注意y的判断还要满足前一个字符不是元音字母(aeiou)就可以了。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 char dict[25][2][25] ; 6 int n, m ; 7 8 9 int find(char s[])10 {11 int i ;12 for (i = 0 ; i < n ; i++)13 if ... 阅读全文

posted @ 2012-05-03 05:01 Seraph2012 阅读(246) 评论(0) 推荐(0)

hdu 1978
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1978题意:中文。mark:水题。可以dfs搞,也可以dp搞,此处是dp。写错下标wa了1次,忘记删调试信息ole一次。太2了。代码: 1 # include <stdio.h> 2 3 4 # define MOD 10000 5 6 7 int a[110][110], dp[110][110] ; 8 int n, m ; 9 10 11 int calc(int x, int y)12 {13 int i, j, rtn = 0 ;14 if (x == n-1 && 阅读全文

posted @ 2012-05-03 04:45 Seraph2012 阅读(267) 评论(0) 推荐(0)

hdu 2184
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2184题意:中文。。。就是递归了。代码: 1 # include <stdio.h> 2 3 4 int n ; 5 long long m ; 6 7 8 int pil[3][70] ; 9 10 11 void gao(int a[], int b[], int c[])12 {13 long long mid = (1LL << (n-1)) ;14 if (n == 0) return ;15 if (m >= mid)16 {17 c[... 阅读全文

posted @ 2012-05-03 03:35 Seraph2012 阅读(191) 评论(0) 推荐(0)

hdu 1997
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1997题意:中文。。。mark:生生递归就好了。代码: 1 # include <stdio.h> 2 3 4 int num[4] ; 5 int pil[4][70] ; 6 int n ; 7 8 9 int judge(int a[70], int b[70], int c[70], int na, int nb, int nc)10 {11 // printf ("%d\n", n) ;12 if (n == 0) return 1 ;13 if (na < 阅读全文

posted @ 2012-05-03 02:44 Seraph2012 阅读(218) 评论(0) 推荐(0)

hdu 1992
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1992题意:用1*2和2*1的小长方形铺垫4*W的方格有多少种方法。mark:这题真是一个非常有意思的题目,第一眼看,觉得应该是很简单的递推题,但是又秒不掉,灰常让人捉集。首先递推总是想着从后往前由已知解来推出新解。这题很容易想到当W为n的时候,用n-1的结果加上两个竖杠和n-2的结果加上题目分析的那五种中不和n-1重复的4种情况来构造。但是但是但是,这是不完全的。在推导W=3的情况时发现只有9种,然而按题目应该是11种。想了很久才发现漏掉了以下这种情况(由于对称,因此少2种): -- -- --| . 阅读全文

posted @ 2012-05-02 12:53 Seraph2012 阅读(754) 评论(1) 推荐(0)

hdu 1988
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1988题意:n块煎饼,尺寸分别为1至n,从上到下堆成一堆。正面朝上为+,反面朝上为-。每次可以选择上面若干块整个翻转过来。求翻转的步骤,能使得最后正面朝上,尺寸从上到下是小到大。mark:没啥困难的,每次选最大的那个经过不超过3次操作翻到最底下。sample给得很好,主要是注意最顶上1的处理就可以了。代码: 1 # include <stdio.h> 2 3 4 int n, a[35] ; 5 int ans[110], cnt ; 6 7 8 int abs(int x){return 阅读全文

posted @ 2012-05-01 12:22 Seraph2012 阅读(293) 评论(0) 推荐(0)

hdu 1987
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1987题意:就是1986的逆向。。。解码。mark:要注意的是要去掉解码出来的字符串的结尾空格。如果字符串是空串,数字和字符串之间的空格不需要去掉。一直PE,后来发现是去结尾空格的时候,i = len - 1写成了i = len。。。太2了。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 char str[410] ; 6 char out[25][25] ; 7 char ss[100], ssout[110] ; 阅读全文

posted @ 2012-05-01 10:49 Seraph2012 阅读(174) 评论(0) 推荐(0)

hdu 1986
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1986题意:按要求把字母或空格字符串扩展成5个01字符表示的字符串以后,缠绕放置在一个r*c的矩阵里。最后一排一排输出。mark:各种wa。后来才发现是输入的问题。当字符串长度为0的时候,我本来用的是scanf的正则输入,结果事实证明不行。。。另外用来放置扩展以后的字符串的字符数组ss一开始忘记清0也wa了一次。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 char str[100] ; // less than 8 阅读全文

posted @ 2012-04-27 23:03 Seraph2012 阅读(303) 评论(0) 推荐(0)

hdu 1981
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1981题意:给长度为n的小写字母字符串,有3种操作:"Q A":输出当前字符串的第A个字符;"S A B":把第A个到第B个字符都加1。a变成b,b变成c,z变成a。。。"R A B":把从A到B的字符串逆转。输出就是Q操作的时候的输出。mark:这题真是tricky。一看8w个字符,先知道直接搞是肯定不行的。后来想了一下也没想到好办法。查了一下,原来可以记录下每次的操作,然后查询的时候根据位置往前循环,因为查找次数少,因而效率比较高。一开始w 阅读全文

posted @ 2012-04-27 09:05 Seraph2012 阅读(276) 评论(0) 推荐(0)

hdu 1673
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1673题意:一条路上有n家商店,给出坐标。某人停车在某点后,要逛完所有商店回到车出。停车地点自选,求最少需要步行多远。mark:唬人,其实就是最大值与最小值差的两倍。代码: 1 # include <stdio.h> 2 3 4 int main () 5 { 6 int T, n, num ; 7 int max, min ; 8 scanf ("%d", &T) ; 9 while (T--)10 {11 scanf ("%d", & 阅读全文

posted @ 2012-04-27 06:36 Seraph2012 阅读(276) 评论(0) 推荐(0)

hdu 1236
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1236题意:中文名。这种排序题已经无力吐槽了。敲错变量tle了一次- -。代码: 1 # include <stdio.h> 2 # include <stdlib.h> 3 # include <string.h> 4 5 6 typedef struct STU{ 7 char name[25] ; 8 int scr ; 9 }STU ;10 11 12 STU stu[1010] ;13 int scr[15] ;14 15 16 int cmp (const 阅读全文

posted @ 2012-04-27 06:32 Seraph2012 阅读(273) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 ··· 24 下一页