杭电-acm
- 格式:docx
- 大小:148.28 KB
- 文档页数:41
1040 As Easy As A+BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26015 Accepted Submission(s): 11054Problem DescriptionThese days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.Give you some integers, your task is to sort these number ascending (升序).You should know how easy the problem is now!Good luck!InputInput contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line.It is guarantied that all integers are in the range of 32-int.OutputFor each case, print the sorting result, and one line one case.问题描述这些天来,我在思考一个问题,我怎样才能得到一个简单的问题,因为A + B?这是相当困难做这样的事情。
Problem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2#include<stdio.h>void main(){int a,b;while(scanf("%d %d",&a,&b)!=EOF){printf("%d\n",a+b);}}Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.InputThe input will consist of a series of integers n, one integer per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.Sample Input1100Sample Output15050#include<stdio.h>void main(){int n,sum,i;while(scanf("%d",&n)!=EOF){sum=0;for( i=0;i<=n;i++)sum+=i;printf("%d\n\n",sum);}}Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 +2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110 #include<stdio.h>#include<string.h>int main(){char str1[1001], str2[1001];int t, i, len_str1, len_str2, len_max, num = 1, k;scanf("%d", &t);getchar();while(t--){int a[1001] = {0}, b[1001] = {0}, c[1001] = {0};scanf("%s", str1);len_str1 = strlen(str1);for(i = 0; i <= len_str1 - 1; ++i)a[i] = str1[len_str1 - 1 - i] - '0';scanf("%s",str2);len_str2 = strlen(str2);for(i = 0; i <= len_str2 - 1; ++i)b[i] = str2[len_str2 - 1 - i] - '0';if(len_str1 > len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i <= len_max - 1; ++i){c[i] = (a[i] + b[i] + k) % 10;k = (a[i] + b[i] + k) / 10;}if(k != 0)c[len_max] = 1;printf("Case %d:\n", num);num++;printf("%s + %s = ", str1, str2);if(c[len_max] == 1)printf("1");for(i = len_max - 1; i >= 0; --i){printf("%d", c[i]);}printf("\n");if(t >= 1)printf("\n");}return 0;}Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5Sample OutputCase 1:14 1 4Case 2:7 1 6注:最大子序列是要找出由数组成的一维数组中和最大的连续子序列。
杭州电子科技大学acm答案杭电2000~A+B for Input-Output Practice (VIII)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5573 Accepted Submission(s): 2058Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.OutputFor each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156正确代码:#includeusing namespace std;int main(){int m,n,i,j,s,k;cin>>n;int c[1000];for(i=0;i<n;i++)< p="">{cin>>m;s=0;for(j=1;j<=m;j++){cin>>k;s+=k;}if(i==n-1){cout<<s<<endl;< p="">}else{cout<<s<<endl<<endl;< p="">}}return 0;}A+B ComingTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 902 Accepted Submission(s): 456Problem DescriptionMany classmates said to me that A+B is must needs. If youcan’t AC this problem, you would invite me for night meal. ^_^ InputInput may contain multiple test cases. Each case contains A and B in one line. A, B are hexadecimal number. Input terminates by EOF.OutputOutput A+B in decimal number in one line.Sample Input1 9A Ba bSample Output102121正确代码:#includeusing namespace std;int main(){int m,n,s;while(scanf("%x%x",&m,&n)!=EOF) //以十六进制输入{s=m+n;printf("%d\n",s); //以十进制输出,与上面}return 0;}此题的输入输出没有用cin>> 和cout<<,看到很多人说scanf和printf比较常用2001ASCII码排序Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T otal Submission(s): 32853 Accepted Submission(s): 13545Problem Description输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
ACM入门(杭电oj)Hdu 1000#include<stdio.h>#include<stdlib.h>int main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF){printf("%d\n",a+b);}}Hdu 1001#include<stdio.h>#include<stdlib.h>int main(){int n;while(scanf("%d",&n)!=EOF){printf("%I64d\n\n",(__int64)(1+n)*n/2); }}Hdu 1002#include<stdio.h>#include<string.h>#include<stdlib.h>char str1[1005],str2[10005];int main(){int ca,count=0;scanf("%d",&ca);while(ca--){scanf("%s%s",str1,str2);int a[1005],i,j;memset(a,0,sizeof(a));for(i=strlen(str1)-1,j=0;i>=0;i--,j++)a[j]=str1[i]-'0';for(i=strlen(str2)-1,j=0;i>=0;i--,j++){a[j]=a[j]+str2[i]-'0';a[j+1]=a[j+1]+a[j]/10;a[j]=a[j]%10;}count++;printf("Case %d:\n",count);printf("%s + %s = ",str1,str2); int flag=0;for(i=1004;i>=0;i--)if(flag||a[i]){printf("%d",a[i]);flag=1;}printf("\n");if(ca!=0) printf("\n");}}Hdu 1003#include<stdio.h>#include<stdlib.h>int a[100005],sum[100005];int main(){int ca,count=0;scanf("%d",&ca);while(ca--){int n,i;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);sum[1]=a[1];int r=1,max=a[1];for(i=2;i<=n;i++){if(sum[i-1]>0){sum[i]=sum[i-1]+a[i];if(sum[i]>max){max=sum[i];r=i;}}else{sum[i]=a[i];if(sum[i]>max){max=sum[i];r=i;}}}count++;for(i=r-1;i>0;i--)if(sum[i]<0) break;printf("Case %d:\n",count);printf("%d %d %d\n",max,i+1,r); if(ca!=0) printf("\n");}}Hdu 1004#include<iostream>#include<algorithm>using namespace std;struct point{char c[50];}p[1005];int cmp(point p1,point p2){return strcmp(p1.c,p2.c)<0;}int main(){int n,i;while(scanf("%d",&n)!=EOF&&n) {for(i=0;i<n;i++)scanf("%s",p[i].c);sort(p,p+n,cmp);char res[100];strcpy(res,p[0].c);int num=1,ct=1;for(i=1;i<n;i++){if(strcmp(p[i].c,p[i-1].c)==0) num++; else num=1;if(num>ct){strcpy(res,p[i].c);ct=num;}}printf("%s\n",res);}}Hdu 1005#include<stdio.h>#include<stdlib.h>#include<string.h>int s[10][10],c[1000];int main(){c[1]=1;c[2]=1;int a,b,n;while(scanf("%d%d%d",&a,&b,&n)!=EOF){if(a==0&&b==0&&n==0) break;memset(s,0,sizeof(s));s[1][1]=1;int i;for(i=3;;i++){c[i]=(a*c[i-1]+ b*c[i-2])%7;if(s[c[i-1]][c[i]]!=0) break;s[c[i-1]][c[i]]=i-1;}/*for(int j=1;j<=i;j++)printf("%d ",c[j]);*/int m=s[c[i-1]][c[i]]-1;int len=i-1-s[c[i-1]][c[i]];//printf("%d %d\n",m,len);if(n<=m){printf("%d\n",c[n]);continue;}n=n-m;printf("%d\n",c[m+(n%len? n%len:len)]); }}Hdu 1008#include<stdio.h>#include<stdlib.h>int main(){int n;while(scanf("%d",&n)!=EOF&&n){int a,sum=0,st=0,m=n;while(n--){scanf("%d",&a);sum=sum+(a-st>0?(a-st)*6:(st-a)*4); st=a;}printf("%d\n",m*5+sum);}}Hdu 1012#include<stdio.h>int main(){printf("n e\n");printf("- -----------\n");printf("0 1\n");printf("1 2\n");printf("2 2.5\n");printf("3 2.666666667\n");printf("4 2.708333333\n");printf("5 2.716666667\n");printf("6 2.718055556\n");printf("7 2.718253968\n");printf("8 2.718278770\n");printf("9 2.718281526\n");}#include<stdlib.h>#include<string.h>#include<stdio.h>int main(){char s[1000];while(scanf("%s",s)!=EOF){if(strcmp(s,"0")==0) break;int i,t=0;for(i=0;i<strlen(s);i++)t=t+s[i]-'0';printf("%d\n",(t+8)%9+1);}}Hdu 1016#include<stdio.h>#include<string.h>inta[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61, 67,71,73};int num[25],flag[25],pri[100],n;void dsf(int x,int y){int i;if(y==n){if(pri[x+1]==1){for(i=1;i<n;i++)printf("%d ",num[i]);printf("%d\n",num[i]);}return;}for(i=2;i<=n;i++)if(flag[i]==0&&pri[x+i]==1){flag[i]=1;num[y+1]=i;dsf(i,y+1);flag[i]=0;}int main(){int ct=0,i;memset(pri,0,sizeof(pri));for(i=0;i<15;i++)pri[a[i]]=1;while(scanf("%d",&n)!=EOF){memset(flag,0,sizeof(flag)); printf("Case %d:\n",++ct);flag[1]=1;num[1]=1;dsf(1,1);printf("\n");}}。
hdu博弈,这些题都不难。
属于博弈简单题。
hdu1846巴什博弈,n%(m+1)==0先手必败。
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;int main(){int n,a,b;scanf("%d",&n);while(n--){scanf("%d%d",&a,&b);if(a%(b+1)==0)printf("second\n");else printf("first\n");}return 0;}hdu1847只要留下两类都是2的指数幂,就是必输状态,然后找规律,发现这两类的和为3的倍数。
即有下面的结论。
#include <iostream>#include<cstdio>#include<cmath>using namespace std;int main(){int n;while(scanf("%d",&n)!=EOF){if(n%3==0)printf("Cici\n");else printf("Kiki\n");}return 0;}hdu1848#include <iostream>#include<cstdio>#include<cmath>#include<cstring>using namespace std;#define N 1005int f[N];int sg[N];void fun(){int i;f[0]=1;f[1]=1;f[2]=2;for(i=3;;i++){f[i]=f[i-1]+f[i-2];if(f[i]>1000)break;}}int dfs(int v){int i;if(sg[v]!=-1)return sg[v];bool visit[N]={0};for(i=1;i<16;i++){if(v>=f[i]){int temp=dfs(v-f[i]);visit[temp]=1;}}for(i=0;visit[i];i++);return sg[v]=i;}int main(){fun();int m,n,p;while(scanf("%d%d%d",&m,&n,&p),m||n||p) {memset(sg,-1,sizeof(sg));int ans;ans=dfs(m)^dfs(n)^dfs(p);if(ans)printf("Fibo\n");else printf("Nacci\n");}return 0;}hdu1849裸的NIM博弈,直接异或即可。
杭电ACM博弈题合集hdu博弈,这些题都不难。
属于博弈简单题。
hdu1846巴什博弈,n%(m+1)==0先手必败。
#include#include#include#include#includeusing namespace std;int main(){int n,a,b;scanf("%d",&n);while(n--){scanf("%d%d",&a,&b);if(a%(b+1)==0)printf("second\n");else printf("first\n");}return 0;}hdu1847只要留下两类都是2的指数幂,就是必输状态,然后找规律,发现这两类的和为3的倍数。
即有下面的结论。
#include#include#includeusing namespace std;int main(){int n;while(scanf("%d",&n)!=EOF) {if(n%3==0)printf("Cici\n");else printf("Kiki\n");}return 0;}hdu1848#include#include#include#includeusing namespace std;#define N 1005int f[N];int sg[N];void fun(){int i;f[0]=1;f[1]=1;f[2]=2;for(i=3;;i++){f[i]=f[i-1]+f[i-2];if(f[i]>1000)break;}}int dfs(int v){int i;if(sg[v]!=-1)return sg[v];bool visit[N]={0};for(i=1;i<16;i++){if(v>=f[i]){int temp=dfs(v-f[i]);visit[temp]=1;}}for(i=0;visit[i];i++);return sg[v]=i;}int main(){fun();int m,n,p;while(scanf("%d%d%d",&m,&n,&p),m||n||p) { memset(sg,-1,sizeof(sg));int ans;ans=dfs(m)^dfs(n)^dfs(p);if(ans)printf("Fibo\n");else printf("Nacci\n");}return 0;}hdu1849裸的NIM博弈,直接异或即可。
杭电ACM丨与名校相抗衡,在国际上频频斩获大奖,有何秘诀?崔倍宁是黑龙江佳木斯人,身高1米84,标准的帅小伙。
这个一脸稚气的东北小鲜肉,现在是杭电自动化学院大一学生。
不久前,他应国内自动驾驶明星企业Momenta之邀,与一群来自清华、北大、浙大的精英学生,一起被挑中成为这家估值上百亿的独角兽公司的“火箭计划20人小组”。
“很难想象,一名省属重点大学的学生,在人工智能高科技公司眼中,可以与北清学生一起探讨最前沿的技术。
但我也不意外,ACM 让我坐上了直升机,在某些领域,可以与国内最优秀的学生同台竞技。
”崔贝宁告诉记者。
“打ACM,进杭电是首选之一”(崔倍宁:杭电大一学生,ACM亚洲区域赛金牌获得者,Momenta火箭计划实习生)崔倍宁高中是在佳木斯一中读的。
现在回想起来,他感到“整个高中基本是在做信奥(OI)题,很苦,但也很酷,当然成就感也是一般人难以体会到的”。
崔倍宁所在的佳木斯一中是黑龙江三所信奥强校之一。
高一时零基础的崔倍宁就因“难得的天赋”被教练看中,连续刷了两年信奥题,取得了信奥国决铜牌。
当时只要高考正常发挥,凭借自主招生上985名校十拿九稳。
但是高考发挥失常的小崔,没有圆成名校梦。
天性乐观的崔倍宁,很快调整心态,决定选择一所“打ACM氛围好”的大学。
众所周知,信奥(OI)是中国计算机协会主办的,主要考的是编程、算法,在高中阶段叫信奥,采取的是“一个人5个小时做3道难题”的考法。
基本上是同样的题目,到了大学阶段则叫ACM—ICPC,是由美国计算机协会主办的全球性程序设计竞赛,被誉为“大学里难度最高的学科竞赛之一”,采取的是“三个人组队5小时做10—13道题目”的考法,一般前十道题相对容易一些,后三道题超难,比信奥题都难。
高中阶段被推至神坛的信奥,到了大学阶段以ACM的面目,被更多的勇于挑战的学生所熟知拥抱。
“高中时信奥拿的是国决铜牌,其实有点不甘心,暗暗下了决心,上大学一定要至少拿个ACM亚洲区域赛金牌,如果能打入全球总决赛,就会很圆满了。
杭电OJ:1089----1096(c++)(ACM⼊门第⼀步:所有的输⼊输出格式)1089:输⼊输出练习的A + B(I)问题描述您的任务是计算a + b。
太容易了?!当然!我专门为ACM初学者设计了这个问题。
您⼀定已经发现某些问题与此标题具有相同的名称,是的,所有这些问题都是出于相同的⽬的⽽设计的。
输⼊项输⼊将由⼀系列由空格隔开的整数对a和b组成,每⾏⼀对整数。
输出量对于每对输⼊整数a和b,应该在⼀⾏中输出a和b的总和,并且在输⼊中每⾏输出⼀⾏。
样本输⼊1 5 10 20样本输出6 30题解:#include<cstdio>#include<iostream>using namespace std;int main(){int a, b,sum;while(cin >> a >> b){sum = a+b;cout << sum << endl;}return 0;}1090:投⼊产出练习的A + B(II)问题描述您的任务是计算a + b。
输⼊项输⼊的第⼀⾏包含⼀个整数N,然后是N⾏。
每⾏由⼀对整数a和b组成,每对之间⽤空格隔开,每⾏⼀对整数。
输出量对于每对输⼊整数a和b,应该在⼀⾏中输出a和b的总和,并且在输⼊中每⾏输出⼀⾏。
样本输⼊2 1 5 10 20样本输出6 30题解:#include<cstdio>#include<iostream>using namespace std;int a,b,n,sum;cin >> n;while (n){cin >> a >> b;sum = a + b;cout << sum << endl;n--;}return 0;}1091:投⼊产出练习的A + B(III)问题描述您的任务是计算a + b。
2012/5/9 LEEREVWARE HDUACM[键入文档副标题] | AdministratorMax Sum Plus Plus(1024)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9131 Accepted Submission(s): 2993Problem DescriptionNow I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.Given a consecutive number sequence S1, S2, S3, S4 ... S x, ... S n(1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ S x≤ 32767). We define a function sum(i, j) = S i + ... + S j(1 ≤ i ≤ j ≤ n).Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(i m, j m) maximal (i x≤ i y≤ j x or i x≤ j y≤ j x is not allowed).But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(i x, j x)(1 ≤ x ≤ m) instead. ^_^InputEach test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... S n. Process to the end of file.OutputOutput the maximal summation described above in one line.Sample Input1 3 12 32 6 -1 4 -23 -2 3N!(1042)Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 31255 Accepted Submission(s): 8631Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N!InputOne N in one line, process to the end of file.OutputFor each N, output N! in one line.Sample Input123Sample Output126#include <stdio.h>int main(){int i,j,n,u,arry;while(scanf("%d",&n)!=EOF){int a[10000]={1};u=0;for(i=1;i<=n;i++){arry=0;for(j=0;j<=u;j++){arry+=a[j]*i;a[j]=arry%10000;arry/=10000;}if(arry){u++;a[u]=arry;}}printf("%d",a[u]);for(i=u-1;i>=0;i--)printf("%04d",a[i]);printf("\n");}return 0;}Max Sum(1003)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 75802 Accepted Submission(s): 17388Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5Sample OutputCase 1:14 1 4Case 2:7 1 6#include <stdio.h>int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);int i,j,t,n,m,x1,x,y,max,a;scanf("%d",&t);for(i=1;i<=t;i++){scanf("%d",&n);m=0;x1=0;x=0;y=0;max=-1000;for(j=0;j<n;j++){scanf("%d",&a);if(m<0){m=a;x1=j;}elsem+=a;if(max<m){max=m;x=x1;y=j;}}printf("Case %d:\n%d %d %d\n",i,max,x+1,y+1);}return 0;}Let the Balloon Rise(1004)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40420 Accepted Submission(s): 14044Problem DescriptionContest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.This year, they decide to leave this lovely job to you.InputInput contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.A test case with N = 0 terminates the input and this test case is not to be processed.OutputFor each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.Sample Input5greenredblueredred3pinkorangepinkSample Outputredpink#include <stdio.h>#include<string.h>int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);int i,j,k,n,l,max;char str[1000][15];while(scanf("%d",&n)!=EOF&&n){getchar();int a[1000]={0};char ch[1000][15]={""};for(i=0;i<n;i++)scanf("%s",str[i]);strcpy(ch[0],str[0]);j=0;a[0]=1;for(i=1;i<n;i++){l=0;for(k=0;k<=j;k++)if(strcmp(str[i],ch[k])==0){l=1;a[k]++;break;}if(l==0){j++;strcpy(ch[j],str[i]);a[j]++;}}max=0;for(i=0;i<=j;i++)if(max<a[i]){max=a[i];k=i;}printf("%s\n",ch[k]);}return 0; }Tick and Tick(1006)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4797 Accepted Submission(s): 1284Problem DescriptionThe three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest. You are to calculate how much time in a day that all the hands are happy.InputThe input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1.OutputFor each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places.Sample Input12090-1Sample Output100.0000.0006.251严重超时(需改进算法)#include <stdio.h>double g(double a,double b){while(a>360)a-=360;while(b>360)b-=360;double min;if(a<b)min=(b-a<a-b+360?b-a:a-b+360);elsemin=(a-b<b-a+360?a-b:b-a+360);return min;}double f(double a,double b,double c){double min=g(a,b);min=(min<g(b,c)?min:g(b,c));min=(min<g(a,c)?min:g(a,c));return min;}int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);double t,s,m,h,a,num;double p;while(scanf("%lf",&a)!=EOF&&a!=-1){num=0;for(t=0;t<43200;t+=0.01){s=t*6;m=t/10.0;h=t/120.0;if(f(s,m,h)>=a)num+=0.01;}p=num/432.0;printf("%.3lf\n",p);}return 0; }改进后#include <stdio.h>double g(double a,double b){double min;if(a<b)min=(b-a<a-b+360?b-a:a-b+360);elsemin=(a-b<b-a+360?a-b:b-a+360);return min;}double f(double a,double b,double c){double min=g(a,b);min=(min<g(b,c)?min:g(b,c));min=(min<g(a,c)?min:g(a,c));return min;}int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);double t,s,m,h,a,num;double p;while(scanf("%lf",&a)!=EOF&&a!=-1){num=0;s=0;m=0;h=0;for(t=0;t<43200;t+=0.1,s+=0.6,m+=0.01,h+=0.000833333) {if(s>360)s-=360;if(m>360)m-=360;if(f(s,m,h)>=a)num+=0.1;}p=num/432.0;printf("%.3lf\n",p);}return 0;}钥匙计数之二(1480)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 692 Accepted Submission(s): 419Problem Description一把钥匙有N个槽,2<N<26槽深为1,2,3,4,5,6。