摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1850题意:中文……mark:Nim游戏,参见http://baike.baidu.com/view/1101962.htm代码:#include <stdio.h>int main(){ int m,a[110]; int i,n,sum; while(scanf("%d", &m), m) { for(i = n = 0; i < m; i++) { scanf("%d", a+i); n ^= a[i]...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1847题意:中文……mark:wa了一次,题目看错了,以为是只能按照1,2,4……的顺序来取牌。 数据比较小,博弈问题,在纸上找到规律了,直接暴力破解了。代码:#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) ...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1069题意:给定若干个木块长宽高,长宽高可以自己调整,求堆积起来最高的高度。mark:枚举所有木块长宽高可能情况,简单dp。代码:#include <stdio.h>#include <stdlib.h>typedef struct{ int x,y,z;}block;int cmp1(const void *a, const void *b){ block *p = (block *)a, *q = (block *)b; if(p->x != q->x) retu
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1087题意:只能走比当前旗子大的旗子,不能回头,求走过最大的旗子的和。mark:简单dp。代码:#include <stdio.h>#include <string.h>int main(){ int n,a[1010],dp[1010][2]; int i,j,max; while(scanf("%d", &n), n) { memset(dp, 0, sizeof(dp)); for(i = 0; i < n; i++) sc...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2151题意:中文……mark:递推。dp[i][j]代表第i时刻在第k棵树的方法数。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; int i,j; while(~scanf("%d%d%d%d", &n, &p, &m, &t)) {
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=2108题意:给定一个多边形的每一个顶点坐标,判断它是否为凸多边形。mark:判断每两个向量的转向。wa了2次,tle了1次。把文件输入输出部分一起交了……代码:#include <stdio.h>int main(){ int n,x1,x2,x3,y1,y2,y3,f,x0,y0,x4,y4; while(scanf("%d", &n), n) { if(n < 3) { while(n--) scanf...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1391题意:按图输出图上数字。mark:模仿图形里面数字变换特性。代码:#include <stdio.h>int a[5010][2];int main(){ int n,x,y,m; int i; a[0][0] = 0; a[1][1] = 1; i = m = 2; while(i < 5001) { a[i++][0] = m++; a[i--][0] = m++; a[i++][1] = m++; ...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1035题意:看小人是否能走出迷宫。mark:wa了一次,又是循环跳出条件出问题了……代码:#include <stdio.h>#include <string.h>int main(){ char a[15][15]; int m,n,s,sum,b[15][15]; int i,j,k; while(scanf("%d%d", &m, &n), m+n) { scanf("%d", &s); for(i = 0;
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1785题意:按原点到给定点的向量与x轴正方向夹角大小排序,夹角越小,实际越大。mark:wa了两次。。。题目说的是与x轴正方向的夹角。。代码:#include <stdio.h>#include <stdlib.h>typedef struct{ double x,y;}stu;int cmp(const void *a, const void *b){ stu *p = (stu *)a, *q = (stu *)b; double m; m = p->y*q->x
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1396题意:等边三角形每一条边被分成n份后,总共有多少个等边三角形。mark:wa了一次,把问题想简单了……没考虑反着的大三角形,应该分奇偶考虑。代码:#include <stdio.h>int main(){ int i,m,a[501] = {0,0}, b[501] = {0,1}; m = 1; for(i = 2; i < 501; i++) { m += i; b[i] = b[i-1] + m; a[i] = a[i-2] ...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1859题意:中文……mark:就是找x,y中出现过的最大最小数。循环跳出条件需要注意~代码:#include <stdio.h>int main(){ int x1,x2,y1,y2,x,y; x1 = y1 = 232; x2 = y2 = -232; while(scanf("%d%d", &x, &y)) { if(!x && !y) { if(x1 == 232) break; printf("...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1716题意:中文……mark:只有四位数,直接暴力破了。。代码:#include <stdio.h>#include <stdlib.h>int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main(){ int a[4],sum,p1,p2; int i,j,k,s,f; f = 0; while(scanf("%d%d%d%d", a, a+1, a+2, a+3
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1256题意:中文……mark:写的中间就发现用自定义函数会少很多代码。。代码:#include <stdio.h>int main(){ int n,m,p,s; int i,j,k; char a; scanf("%d%*c", &n); k = 0; while(n-- && scanf("%c %d%*c", &a, &m)) { if(k++) puts(""); s = m/6+1;
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1088题意:按要求输出html文件。mark:pe了无数次,主要是临界问题的考虑,还有是要考虑'\t'。代码:#include <stdio.h>int zh(char a){ if(a == '<') return 1; if(a == ' ' || a == '\n' || a == '\t') return 2; return 3;}int main(){// freopen("in1.tx
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1197题意:求一个数转换成10,12,16进制后各个位上的数的和是否相等。mark:模拟进制转换。代码:#include <stdio.h>int zh(int a, int n){ int sum = 0; while(a) { sum += a%n; a /= n; } return sum;}int main(){ int m; for(m = 2992; m < 10000; m++) if(zh(m, 10) ...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1194题意:赌球,用比分的和与比分的差的绝对值赌博。mark:注意比分都是整数。代码:#include <stdio.h>int main(){ int t,m,n; scanf("%d", &t); while(t-- && scanf("%d%d", &m, &n)) if(m < n || (m+n) & 1) puts("impossible"); else printf
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1143题意:3*n的矩形用2*1的砖堆法。mark:wa了,两次。。一次数组只开到30了,一次循环跳出条件写错了。。囧……递推就ok了。 我是画图一步一步推出来的。首先肯定是2个2个增加的。首先考虑不交叉的f(n) = 3*f(n-2),再考虑交叉的,会发现规律,2*(f(n-4)+f(n-6)+……) ps:后来看大牛的代码,发现公式化简了可以降低复杂度,虽然这题n最大才30。f(n) = 4*f(n-2)-f(n-4)代码:#include <stdio.h>int main(){ ..
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1098题意:给定k,求满足任何x都能使f(x)能被65整除的a的值。mark:本题要用欧拉定理,一开始完全不会啊。。。欧拉定理证明http://baike.baidu.com/view/48903.htm 从65着手。65=13*5,所以要f(x)被65整除,那么f(x)一定整除13和5。 先考虑13。f(x)=13*x^5 + 5*x^13 + k*a*x,13*x^5显然是13的倍数。所以只用考虑5*x^13+k*a*x = x*(5*x^12+k*a)。 1.当x能被13整除的时候...
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1039题意:判断密码是否可行。满足三个条件:1.至少一个元音字母。2.连续三个字母不能同时为元音或辅音。3.连续两个字母不能相同,但是不包括"ee"和"oo"。mark:无。代码:#include <stdio.h>#include <string.h>int yy(char a){ if(a == 'a' || a == 'e' || a == 'i' || a == 'o'
阅读全文
摘要:地址:http://acm.hdu.edu.cn/showproblem.php?pid=1037题意:货物的高度能否通过给定高度的障碍物。mark:无代码:#include <stdio.h>int main(){ int a[3],i; while(~scanf("%d%d%d", a, a+1, a+2)) { for(i = 0; i < 3; i++) if(a[i] <= 168) break; if(i == 3) puts("NO CRASH"); else printf("CRASH %d\n"
阅读全文