摘要: 地址: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 阅读(541) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(254) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(349) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(377) 评论(0) 推荐(0) 编辑
摘要: 地址: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 阅读(169) 评论(0) 推荐(0) 编辑