Problem A
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 33 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
你可以认为32位整数足以保存结果。
Sample Input
1 3 2 5
Sample Output
4 28 20 152
#include<stdio.h> #define swap(a,b) {a=a+b; b=a-b; a=a-b;} int main() { int x,y,i,ans1,ans2; while(scanf("%d %d",&x,&y)!=EOF) { ans1=0; ans2=0; if(x>y) swap(x,y); for(i=x;i<=y;i++) { if(i%2) ans2+=i*i*i; else ans1+=i*i; } printf("%d %d\n",ans1, ans2); } return 0; }
Problem B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 13 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
123 -234.00
Sample Output
123.00 234.00
#include<stdio.h> int main() { double n; while(scanf("%lf",&n)!=EOF) { if(n<0) printf("%.2lf\n",-n); else printf("%.2lf\n",n); } return 0; }
Problem C
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 11 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
0 0 0 1 0 1 1 0
Sample Output
1.00 1.41
#include<stdio.h> #include<math.h> int main() { double x1,x2,y1,y2,ans; while(scanf("%lf %lf %lf %lf",&x1, &y1, &x2, &y2)!=EOF) { ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); printf("%.2lf\n",ans); } return 0; }
Problem D
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
什么问题?他研究的问题是蟠桃一共有多少个!
不过,到最后,他还是没能解决这个难题,呵呵^-^
当时的情况是这样的:
第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子。聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢?
Input
Output
Sample Input
2 4
Sample Output
4 22
#include<stdio.h> int main() { int n,ans,i; while(scanf("%d",&n)!=EOF) { ans=1; for(i=1;i<n;i++) { ans=(ans+1)*2; } printf("%d\n",ans); } return 0; }
Problem E
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 17 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
Output
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120 300 380
Sample Output
no 370 371
循环判断
#include<stdio.h> bool is_shui(int x) { int sum=0,ans=x; while(x!=0) { sum+=(x%10)*(x%10)*(x%10); x/=10; } if(ans==sum) return true; else return false; } int main() { int m,n,i,j; bool flag; while(scanf("%d%d",&m,&n)!=EOF) { flag=false; for(i=m;i<=n;i++) { if(is_shui(i) ) { if(flag) { printf(" "); printf("%d",i); } else { printf("%d",i); flag=true; } } } if(flag) printf("\n"); else printf("no\n"); } }
Problem F
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Consider the following algorithm:
1. input n
2. print n
3. if n = 1 then STOP
4. if n is odd then n <- 3n + 1
5. else n <- n / 2
6. GOTO 2
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that
0 < n < 1,000,000 (and, in fact, for many more numbers than this.)
Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
Input
You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.
You can assume that no opperation overflows a 32-bit integer.
Output
for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
Sample Input
1 10 100 200 201 210 900 1000
Sample Output
1 10 20 100 200 125 201 210 89 900 1000 174
简单模拟,按要求计算程序运行的次数,但是此题也有一个小陷阱,输入的i,j不一定升序,而且在输出时必选按如输入时的顺序输出
#include<stdio.h> #define swap(a,b) {a=a+b; b=a-b; a=a-b;} int whatstep(int num) { int ans=1; while(num!=1) { if(num%2) num=3*num+1; else num/=2; ans++; } return ans; } int main() { int n, m, i, j, max, step; while(scanf("%d %d",&n,&m)!=EOF) { max=0; if(n>m) { i=m; j=n; } else { i=n; j=m; } for(;i<=j;i++) { step=whatstep(i); max=max>step?max:step; } printf("%d %d %d\n",n,m,max); } return 0; }
Problem G
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Descriptio
River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion.
After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The
semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)
Input
Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given.
Output
“Property N: This property will begin eroding in year Z.”
Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer.
After the last data set, this should print out “END OF OUTPUT.”
Notes:
1. No property will appear exactly on the semicircle boundary: it will either be inside or outside.
2. This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines.
3. All locations are given in miles.
Sample Input
2 1.0 1.0 25.0 0.0
Sample Output
Property 1: This property will begin eroding in year 1. Property 2: This property will begin eroding in year 20. END OF OUTPUT.
#include<stdio.h> #include<math.h> #define Pi 3.1415926 int main() { int n,i; scanf("%d",&n); for(i=1;i<=n;i++) { double x,y,r,s; int year; scanf("%lf %lf",&x,&y); r=sqrt(x*x+y*y); s=Pi*r*r; year=ceil(s/2/50); printf("Property %d: This property will begin eroding in year %d.\n", i,year); } printf("END OF OUTPUT.\n"); return 0; }
Preblem H 是个大数,改天专门开一帖讲解。
Problem I
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 4 Accepted Submission(s) : 4
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
If you can’t AC this problem, you would invite me for night meal. ^_^
Input
A, B are hexadecimal number.
Input terminates by EOF.
Output
Sample Input
1 9 A B a b
Sample Output
10 21 21
#include<stdio.h> int main() { int x,y; while(scanf("%x %x",&x, &y)!=EOF) { printf("%d\n",x+y); } return 0; }