西工大noj答案解析完整编辑版.doc
-/西北工业大学POJ答案绝对是史上最全版(不止100题哦按首字母排序)1. “1“的传奇2. A+B3. A+B4. AB5. ACKERMAN6. Arithmetic Progressions7. Bee8. Checksum algorithm9. Coin Test10. Dexter need help11. Double12. Easy problem13. Favorite number14. Graveyard15. Hailstone16. Hanoi 17. Houseboat18. Music Composer19. Redistribute wealth20. Road trip21. Scoring22. Specialized Numbers23. Sticks24. Sum of Consecutive25. Symmetric Sort26. The Clock27. The Ratio of gainers to losers28. VOL大学乒乓球比赛29. 毕业设计论文打印30. 边沿与内芯的差31. 不会吧,又是A+B32. 不屈的小蜗33. 操场训练34. 插入链表节点35. 插入排序36. 插入字符37. 成绩表计算38. 成绩转换39. 出租车费40. 除法41. 创建与遍历职工链表42. 大数乘法43. 大数除法44. 大数加法45. 单词频次46. 迭代求根47. 多项式的猜想48. 二分查找49. 二分求根50. 发工资的日子51. 方差52. 分离单词53. 分数拆分54. 分数化小数55. 分数加减法56. 复数57. 高低交换58. 公园喷水器59. 韩信点兵60. 行程编码压缩算法61. 合并字符串62. 猴子分桃63. 火车站64. 获取指定二进制位65. 积分计算66. 级数和67. 计算A+B68. 计算PI69. 计算70. 计算成绩71. 计算完全数72. 检测位图长宽73. 检查图像文件格式74. 奖金发放75. 阶乘合计76. 解不等式77. 精确幂乘78. 恐怖水母79. 快速排序80. 粒子裂变81. 链表动态增长或缩短82. 链表节点删除83. 两个整数之间所有的素数84. 路痴85. 冒泡排序86. 你会存钱吗87. 逆序整数88. 排列89. 排列分析90. 平均值函数91. 奇特的分数数列92. 求建筑高度93. 区间内素数94. 三点顺序95. 山迪的麻烦96. 删除字符97. 是该年的第几天98. 是该年的第几天?99. 数据加密100. 搜索字符101. 所有素数102. 探索合数世纪103. 特殊要求的字符串104. 特殊整数105. 完全数106. 王的对抗107. 危险的组合108. 文件比较109. 文章统计110. 五猴分桃111. 小型数据库112. 幸运儿113. 幸运数字”7“114. 选择排序115. 寻找规律116. 循环移位117. 延伸的卡片118. 羊羊聚会119. 一维数组”赋值“120. 一维数组”加法“121. 勇闯天涯122. 右上角123. 右下角124. 圆及圆球等的相关计算125. 圆及圆球等相关计算126. 程序员添加行号127. 找出数字128. 找幸运数129. 找最大数130. 整数位数131. 重组字符串132. 子序列的和133. 子字符串替换134. 自然数立方的乐趣135. 字符串比较136. 字符串复制137. 字符串加密编码138. 字符串逆序139. 字符串排序140. 字符串替换141. 字符串左中右142. 组合数143. 最次方数144. 最大乘积145. 最大整数146. 最小整数147. 最长回文子串148. 左上角149. 左下角1 “1“的传奇#include <stdio.h>#include <stdlib.h>#include <math.h>int main() int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0; scanf("%d",&n);m=n;for(i=1;i<12;i+)m=m/10;k+;if(m=0)break;q=n;k=k-1;for(a=1;a<=k;a+)x=x*10;y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10);elses=s+z*k*(x/10);for(j=p;j<=n;j+) m=j; for(i=1;i<12;i+) x=m%10; if(x=1) s+;m=m/10; if(m=0) break; printf("%d",s);return 0;2 A+B#include <stdio.h>int doubi(int n,int m) n=n+m; n=n%100; return n;int main() int t,i,a100,n,m; scanf("%d",&t); for (i=0;i<=(t-1);i+) scanf("%d%d",&n,&m); ai=doubi(n,m); for (i=0;i<=(t-1);i+) printf("%dn",ai); return 0;3 A+B#include <stdio.h>int main()int A,B,sum;scanf("%d%d",&A,&B);sum=A+B; printf("%dn",sum); return 0;4 AB#include <stdio.h>#include <stdlib.h>#include <string.h>int main() char s100,q100; double a,b,c; int n=0,i; scanf("%lf%lf",&a,&b); c=a*b; sprintf(s,"%.0lf",c); for(i=0;i<strlen(s);i+) n=n+si-48; while(n>=10) sprintf(q,"%d",n); n=0; for(i=0;i<strlen(q);i+) n=n+qi-48; printf("%d",n); return 0;5 ACKERMAN#include <stdio.h>#include <stdlib.h>#include <math.h>int ack(int x,int y) int n; if (x=0) n=y+1; return n; else if (y=0) n=ack(x-1,1); else n=ack(x-1,ack(x,y-1); return n;int main() int m,b; scanf("%d%d",&m,&b); m=ack(m,b); printf("%d",m); return 0;6 Arithmetic Progressions#include <stdio.h>#include <stdlib.h>#include <math.h>int g(int n) int i; if(n=1) return 0; if(n=2) return 1; if(n=3) return 1; for(i=2;i<=sqrt(n);i+) if(n%i=0) return 0; return 1;int f(int a,int b,int c) int i=0,s=a-b; if(c=1&&g(a)=1) return a; if(b=0&&g(a)!=1) return -1; while(1) s=s+b; if(g(s) i+; if(i>=c) break; return s;int main() int a,b,c,d100,i=0,n; while(1) scanf("%d%d%d",&a,&b,&c); if(a=0&&b=0&&c=0) break; di=f(a,b,c); i+; n=i; for(i=0;i<n;i+) printf("%dn",di); return 0;7 Bee#include <stdio.h>#include <stdlib.h>int main() int A100,i=0,j,k,female=0,male=1,x; for(;i+)scanf("%d",&Ai);if(Ai=-1)break;for(j=0;j<i;j+)female=0,male=1;for(k=1;k<Aj;k+)x=female;female=male;male=x+male+1;printf("%d %dn",male,female+male+1);return 0;8 Checksum algorithm#include <stdio.h>#include <stdlib.h>#include <string.h>int main()int i,n,t,j; char s100100; for(i=0;i+)gets(si);if(si0=#) break; n=i;for(i=0;i<n;i+)t=0;for(j=0;j<strlen(si);j+)if(sij=32) t=t;else t=t+(j+1)*(sij-64);printf("%dn",t); return 0;9 Coin Test#include <stdio.h>#include <stdlib.h>int main() char A100000; int n,i=0,a=0,b=0,j; double x; while(1)scanf("%c",&Ai);if(Ai=n)break;i+;for(j=0;j<i;j+)if(Aj=S)printf("WA");goto OH;if(Aj=U)a+;if(Aj=D)b+;x=a*1.0/(a+b)*1.0;if(x-0.5>0.003|x-0.5<-0.003)printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;10 Dexter need help#include <stdio.h>int fun(int a)if(a=1) return 1;elsereturn fun(a/2)+1;int main()int a,b100,i=0,j;while(1) scanf("%d",&a); if(a=0)break;bi=fun(a);i+;for(j=0;j<i;j+) printf("%dn",bj);return 0;11 Double#include <stdio.h>#include <stdlib.h>#include <math.h>int main() int a100,b100,i,j,n,t=0; for(i=0;i+) scanf("%d",&ai); if(ai=0) break; n=i; for(i=0;i<n;i+) bi=2*ai; for(i=0;i<n;i+) for(j=0;j<n;j+) if(ai=bj) t+; printf("%d",t); return 0;12 Easy problem#include <stdio.h>#include <stdlib.h>#include <math.h>int main() int N,i,n,j=0; scanf("%d",&N); for(i=2;i<N+1;i+) if(N+1)%i=0)j+; printf("%d",j/2); return 0;13 Favorite number#include <stdio.h>#include <string.h>#define MAXNUM 100000int prime_number = 0;int prime_listMAXNUM;bool is_primeMAXNUM;int ansMAXNUM + 2;int dpMAXNUM + 2;void set_prime() int i, j; memset(is_prime, 0, sizeof(is_prime); for (i = 2; i < MAXNUM; i+) if (is_primei = 0) prime_listprime_number+ = i; if (i >= MAXNUM / i) continue; for (j = i * i; j < MAXNUM; j+=i) is_primej = 1; int main() int i, j, k,o=0,d100; memset(dp, -1, sizeof(dp); set_prime(); ans0 = 0; dp1 = 0; for (i = 1; i <= MAXNUM; i+) ansi = ansi - 1 + dpi; if (dpi + 1 = -1 | dpi + 1 > dpi + 1) dpi + 1 = dpi + 1; for (j = 0; j < prime_number; j+) if (i > MAXNUM / prime_listj) break; k = i * prime_listj; if (dpk = -1 | dpk > dpi + 1) dpk = dpi + 1; while (scanf("%d%d", &i, &j) = 2 && (i | j) do=ansj - ansi - 1; o+; for(i=0;i<o;i+) printf("%dn",di);14 Graveyard#include <stdio.h>#include <stdlib.h>#include <math.h>int main() int a100,b100,n,i,j; double s,p,l,t; for(i=0;i+) scanf("%d%d",&ai,&bi); if(ai=0&&bi=0) break; n=i; for(i=0;i<n;i+) p=10000; if(bi%ai=0)printf("0.0000n");continue; t=10000/(double)ai); for(j=1;j<ai+bi;j+) l=10000/(double)(ai+bi); l=t-j*l; l=fabs(l); if(l<p) p=l; s=(ai-1)*p; printf("%.4lfn",s); return 0;15 Hailstone#include <stdio.h>#include <stdlib.h>#include <string.h>int f(int n) int s=1; while(1) if(n=1) return s; else if(n%2=0) n=n/2,s+; else n=3*n+1,s+; int main() int n,m,i,j=0,t; scanf("%d%d",&m,&n); printf("%d %d",m,n); if(m>n) t=m,m=n,n=t; for(i=m;i<=n;i+) if(f(i)>j) j=f(i); printf(" %d",j); return 0;16 Hanoi #include <stdio.h>#include <stdlib.h>#define M 70int startM, targeM;long long f(int *p, int k, int fina) if(k=0) return 0; if(pk=fina) return f(p,k-1,fina); return f(p,k-1,6-fina-pk)+(1LL<<(k-1);int main () long long ans; int n; while(scanf("%d",&n),n) int i; for(i=1;i<=n;i+) scanf("%d",&starti); for(i=1;i<=n;i+) scanf("%d",&targei); int c=n; for(;c>=1&&startc=targec;c-); if(c=0) printf("0n"); continue; int other=6-startc-targec; ans=f(start,c-1,other)+f(targe,c-1,other)+1; printf("%lldn",ans); return 0;17 Houseboat#include <stdio.h>#include <stdlib.h>#include <math.h>#define pi 3.1415926int f(float x,float y) int i; for(i=0;i+) if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break; return i;int main() int n,i,a100; float x,y; scanf("%d",&n); for(i=0;i<n;i+) scanf("%f%f",&x,&y); ai=f(x,y); for(i=0;i<n;i+) printf("%d %dn",i+1,ai); return 0;18 Music Composer19 Redistribute wealth#include <stdio.h>#include <stdlib.h>#include <math.h>int main() int a1000,b1000,n,i,j,s,sum,t,m,mid,c100,k=0; while(1) scanf("%d",&n); if(n=0) break; s=0; for(i=1;i<=n;i+) scanf("%d",&ai); s=s+ai; m=s/n; b1=a1-m; b0=0; for(i=2;i<n;+i) bi=bi-1+ai-m; for(i=0;i<n;i+) for(j=0;j<n-1-i;j+) if(bj>bj+1) t=bj,bj=bj+1,bj+1=t; mid=bn/2; sum=0; for(i=0;i<=n-1;+i) sum=sum+fabs(mid-bi); ck=sum;k+; for(i=0;i<k;i+) printf("%dn",ci); return 0;20 Road trip#include <stdio.h>#include <stdlib.h>#include <math.h>int f(int n) int a100,b100,i,s; for(i=0;i<n;i+) scanf("%d%d",&ai,&bi); s=a0*b0; for(i=1;i<n;i+) s=s+ai*(bi-bi-1); return s;int main() int n,c100,i=0; while(1) scanf("%d",&n); if(n=-1) break; ci=f(n); i+; n=i; for(i=0;i<n;i+) printf("%dn",ci); return 0;21 Scoring#include <stdio.h>#include <stdlib.h>#include <string.h>int main() int i,j,sum,min,c,count,n,a,b; char s150,s250; scanf("%d",&n); for(i=0;i<n;i+) count=sum=0; scanf("%s",s2); for(j=0;j<4;j+) scanf("%d%d",&a,&b); if(b!=0) sum+=(a-1)*20+b; count+; if(i=0) c=count,min=sum; strcpy(s1,s2); else if(count>c|(count=c&&sum<min) min=sum; c=count; strcpy(s1,s2); printf("%s %d %dn",s1,c,min); return 0;22 Specialized Numbers#include <stdio.h>#include <stdlib.h>int main() int i,n,sum10,sum12,sum16; for(i=2992;i<3000;i+) n=i; sum10=0; while(n) sum10+=n%10; n/=10; n=i; sum12=0; while(n) sum12+=n%12; n/=12; n=i; sum16=0; while(n) sum16+=n%16; n/=16; if(sum10=sum12&&sum12=sum16) printf("%dn",i); return 0;23 Sticks#include <stdio.h>#include <string.h>#include <stdlib.h>int len64, n, minlen, get;bool b64;int cmp(const void *a, const void *b) return *(int *)a < *(int *)b ? 1 : -1;bool dfs(int nowlen, int nowget, int cnt) if(cnt >= n) return false; if(get = nowget) return true; int i; bool f = false; if(nowlen = 0) f = true; for(i = cnt; i < n; i+) if(!bi) if(leni + nowlen = minlen) bi = true; if(dfs(0, nowget+1, nowget) return true; bi = false; return false; else if(leni + nowlen < minlen) bi = true; if(dfs(nowlen+leni, nowget, i+1) return true; bi = false; if(f) return false; while(i + 1 < n && leni = leni+1) i+; return false;int main() int i, tollen; while(scanf("%d", &n), n) tollen = 0; int j = 0, p; for(i = 0; i < n; i+) scanf("%d", &p); if(p <= 50) lenj = p; tollen += lenj; j+; n = j; if(n = 0) printf("0n"); continue; qsort(len, n, sizeof(int), cmp); for(minlen = len0; ; minlen+) if(tollen % minlen) continue; memset(b, 0, sizeof(b); get = tollen / minlen; if(dfs(0, 0, 0) printf("%dn", minlen); break; return 0;24 Sum of Consecutive#include <stdio.h>#include <stdlib.h>#include <string.h>int len64,n,minlen,get;int b64;int cmp(const void *a,const void *b) return *(int *)a<*(int *)b?1:-1;int dfs(int nowlen,int nowget,int cnt) if(cnt>=n) return 0; if(get=nowget)