随笔分类 -  HDOJ

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

发布一些HDOJ的做题情况以及代码。
hdu 2571
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2571题意:中文。mark:水dp。不过边界不太好处理,写成dfs+记忆化比较方便。给2组容易错的数据。应该都输出0。21 2-1 12 1-11代码: 1 # include <stdio.h> 2 3 4 int a[25][1010], vis[25][1010] ; 5 int n, m, INF = 0x0f0f0f0f ; 6 7 8 int max(int a, int b){return a>b?a:b;} 9 10 11 int dfs(int x, int y)12 阅读全文

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

hdu 2570
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2570题意:中文。mark:很水的题。体积V都一样,排序后贪心就可以了。各种wa,主要还是浓度计算那儿装逼不想用实数,就用整数绕过去,结果各种想不清楚。代码: 1 # include <stdio.h> 2 # include <stdlib.h> 3 4 5 int p[110] ; 6 7 int cmp(const void *a, const void *b) 8 { 9 return *(int*)a - *(int*) b ;10 }11 12 13 int main 阅读全文

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

hdu 2569
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2569题意:中文。mark:水递推。很容易得到方程dp[i] = 2*dp[i-1]+dp[i-2]。不过dp[0] = 3。注意要用long long。代码: 1 # include <stdio.h> 2 3 4 long long dp[45] = {3,3} ; 5 6 7 int main () 8 { 9 int T, n, i ;10 for (i = 2 ; i <= 40 ; i++)11 dp[i] = 2*dp[i-1]+dp[i-2] ;1... 阅读全文

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

hdu 2568
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2568题意:中文。mark:看清楚题就好了。就是求二进制表示时1的个数。本来嘛递归直接可以搞,请容我装逼一下用了位运算。。。代码: 1 # include <stdio.h> 2 3 4 int calc(int x){return x?calc(x-(x&-x))+1:0;} 5 6 7 int main () 8 { 9 int T, n ;10 scanf ("%d", &T) ;11 while(T--)12 {13 scanf ("%d 阅读全文

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

hdu 2567
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2567题意:中文。没啥好说的。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 int main () 6 { 7 int T, i, len ; 8 char s1[55], s2[55] ; 9 scanf ("%d", &T) ;10 while (T--)11 {12 scanf ("%s%s", s1, s2) ;13 len = strlen(s1) ;14.. 阅读全文

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

hdu 1800
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1800题意:士兵要学骑扫帚。每个士兵有一个level,level高的能在同一把扫帚上教level低的怎么骑。一个人最多有一个老师,一个学生。也可以没有。给n个士兵的level值,问最少需要多少扫帚。mark:显然就是找出现次数最多的数字的次数。但因为数字长度多达30个字符,因此long long都存不下,用字符串。wa了一次,忘记处理前导0。代码: 1 # include <stdio.h> 2 # include <string.h> 3 # include <stdli 阅读全文

posted @ 2012-04-27 05:24 Seraph2012 阅读(1106) 评论(0) 推荐(1)

hdu 1496
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1496题意:给a,b,c,d。计算有多少组(x1,x2,x3,x4)满足方程。mark:这其实是poj1840的Eqs简化成的问题,是一个经典的hash问题,但是poj是对内存限制严格,此题则是对时间卡的更紧,TLE了好多次。首先将等式分成两边,写成a*x1^2+b*x2^2 = - c*x3^2-d*x4^2,然后枚举其中一边的所有值存起来(hash存),再枚举另一边求解。懒得写hash,直接开200w的数组不是不行,但是很容易TLE。千万不能用O(n)的方式清零数组,应该再执行一次存数时的枚举,原来 阅读全文

posted @ 2012-04-11 05:07 Seraph2012 阅读(549) 评论(0) 推荐(0)

hdu 2094
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2094题意:题目说的不清楚,有很多情况都没说到。不过数据很水,只要判断入度为0的点是否只有1个就可以了。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 int cnt ; 6 char tab[2010][100] ; 7 int degree[2010] ; 8 9 10 int find(char a[])11 {12 int i ;13 for (i = 0 ; i < cnt ; i++)14 i... 阅读全文

posted @ 2012-04-11 04:24 Seraph2012 阅读(256) 评论(0) 推荐(0)

hdu 2093
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2093题意:中文。成绩排序。mark:看似复杂,其实就是个排序,考察基本功。代码: 1 # include <stdio.h> 2 # include <string.h> 3 # include <stdlib.h> 4 5 6 typedef struct NODE{ 7 char name[15] ; 8 int num, time ; 9 }NODE ;10 11 12 NODE stu[1010] ;13 14 15 int cmp(const void * 阅读全文

posted @ 2012-04-11 04:14 Seraph2012 阅读(170) 评论(0) 推荐(0)

hdu 2079
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2079题意:中文。。。mark:母函数。代码: 1 # include <stdio.h> 2 # include <string.h> 3 4 5 int dp[10][45] ; 6 7 8 int main () 9 {10 int T, n, i, j, k, kk ;11 int a, b ;12 scanf ("%d", &T) ;13 while (T--)14 {15 scanf ("%d%d", &n, & 阅读全文

posted @ 2012-04-11 04:01 Seraph2012 阅读(187) 评论(0) 推荐(0)

hdu 1075
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1075题意:在输入的字符串里找词典中的进行替换。mark:诚然,我很讨厌STL,但是这题要是不用STL的话简直太恶心了。最后非常慢。。。将近TLE。代码: 1 # include <iostream> 2 # include <string> 3 # include <map> 4 # include <stdio.h> 5 6 7 using namespace std ; 8 char s[3010] ; 9 10 11 int main ()12 { 阅读全文

posted @ 2012-04-11 03:53 Seraph2012 阅读(232) 评论(0) 推荐(0)

hdu 1071
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1071题意:按图,给出p1,p2,p3的坐标,计算阴影部分面积。mark:就是求公式咯。设y = ax^2 + bx + c。用(x1,y1),(x2,y2)相减再联合顶点坐标(-b/2a, c-b^2/4a)可以轻易求出a,b,c的值。之后算积分就可以了。注意还要减去直线和x轴所夹梯形的面积。代码: 1 # include <stdio.h> 2 # include <math.h> 3 4 5 double fun(double a, double b, double c, 阅读全文

posted @ 2012-04-11 03:29 Seraph2012 阅读(305) 评论(0) 推荐(0)

hdu 1677
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1677题意:俄罗斯套娃是一种有宽w和高h两种属性的玩具。当wi < wj && hi < hj的时候,套娃i能被套在套娃j里。现在给出m个套娃的宽和高,问最少能套出几个套娃。mark:首先按宽度从大到小排序,得到结果以后按高度求最长非降子序列(LIS)。这题和导弹拦截系统问题一样,是经典dp。一开始偷懒写了贪心结果TLE了。代码: 1 # include <stdio.h> 2 # include <stdlib.h> 3 # include < 阅读全文

posted @ 2012-04-11 02:42 Seraph2012 阅读(261) 评论(0) 推荐(0)

hdu 1671
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1671题意:给堆电话号码(数字,长度不大于10),如果有一个号码是另一个号码的前缀就NO,否则YES。mark:trie树来存和查找号码,但是写的有点恶心。代码:# include <stdio.h># include <string.h>typedef struct TRIE{ int end ; int next[10] ;} TRIE ;TRIE trie[100010] ;int cnt ;char tb(char ch){return ch-'0';}i 阅读全文

posted @ 2012-04-11 02:15 Seraph2012 阅读(361) 评论(0) 推荐(0)

hdu 2192
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2192题意:n个size不同的大楼,相同size的不能放在同一MagicBuilding中。问至少要多少个MagicBuilding。mark:其实就是求出现最多的那个数出现的次数,排序以后扫一次就好了。代码:# include <stdio.h># include <stdlib.h>int a[10010] ;int cmp(const void *a, const void *b){ return *(int*)a - *(int*) b ;}int main (){ in 阅读全文

posted @ 2012-04-11 01:55 Seraph2012 阅读(208) 评论(0) 推荐(0)

hdu 1492
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1492题意:丑数(humble number)是一种素因子只有2、3、5、7组成的数字。给一个丑数,问它有多少因数。mark:基础数论。因为只有2、3、5、7四种素因子,因此只要求出幂次,加1后乘起来就好了。注意要用long long。代码:# include <stdio.h>long long div(long long x, int b){ int rtn = 0 ; while (x%b==0) { x /= b ; rtn ++ ; } ... 阅读全文

posted @ 2012-04-11 01:47 Seraph2012 阅读(386) 评论(0) 推荐(0)

hdu 2601
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2601题意:给n,找满足i*j+i+j == n的一对(i,j),其中0<i<=j<n。mark:两边同时+1后得到(n+1)=(i+1)*(j+1)。只要从2到sqrt(n+1)枚举i+1的值就好了。不过时间有点久,2000+ms。正规的做法应该是用数论知识分解素因子。另外要考虑n是10^10,用long long(此处wa了一次)。代码:# include <stdio.h># include <math.h>int main (){ int T, sum, 阅读全文

posted @ 2012-04-11 01:40 Seraph2012 阅读(176) 评论(0) 推荐(0)

hdu 1506
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1506题意:给一些连续的直方柱的高(宽是1),找一个面积最大的矩形。mark:本来是个单调队列题,但是dp好像可以解。考虑每个柱往两边找能扩展到的最远的边界,乘上自己的高可获得。往两边扩展边界的时候理论复杂度是O(n),直接做是要TLE的。先考虑往右找边界,假设之前右边所有的直方柱的边界已经被找过,并且被记录下来,假如下一个柱的高度比自己高,则直接可以跳到下一个柱的边界继续找,不断迭代后很快就能找到边界。不知道这种迭代的方法复杂度如何证明,对于每个柱子,最坏的肯定是要找n次(递减),但是最坏的情况不可能 阅读全文

posted @ 2012-02-26 06:55 Seraph2012 阅读(657) 评论(0) 推荐(0)

hdu 2552
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2552题意:中文。。。mark:无论输入是多少。。。输出都是1。代码:# include <stdio.h>int main (){ int T ; scanf ("%d", &T) ; while (T--) puts("1") ; return 0 ;} 阅读全文

posted @ 2012-02-19 08:29 Seraph2012 阅读(181) 评论(0) 推荐(0)

hdu 2551
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2551题意:中文,直接循环可搞。代码:# include <stdio.h>long long calc(long long x){ long long i, sum = 0 ; for (i = 1 ; ; i++) { sum += i*i*i ; if (sum >= x) break ; } return i ;}int main (){ int T, x ; scanf ("%d", &T) ; while (T--)... 阅读全文

posted @ 2012-02-19 08:16 Seraph2012 阅读(307) 评论(0) 推荐(0)

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