杭电-acm

合集下载

杭电acm题目水题英文题目、翻译及ac源代码

杭电acm题目水题英文题目、翻译及ac源代码

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?这是相当困难做这样的事情。

(完整版)杭电acm部分答案

(完整版)杭电acm部分答案

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注:最大子序列是要找出由数组成的一维数组中和最大的连续子序列。

杭州电子科技大学刘春英-中国大学生程序设计竞赛

杭州电子科技大学刘春英-中国大学生程序设计竞赛

2018/11/6
19
谢谢~
*欢迎提问*
2018/11/6
20
11
二、普通院校的ACM之路



领导重视(必要条件,政策导向) 教练投入(铁打的教练,流水的领导和学生) 积极参与(多参加各类比赛、多交流) 群众基础(AC的不仅仅有集训队员) 科学训练(不同阶段,不同方法) 集体突破(不限于个别优秀学生,HDU2006)
2018/11/6
12
三、具体建议
八、常见问题回答(F.A.Q)
一、教练不懂算法怎么办?(见下个问题) 二、学生英语不好怎么办? 三、是不是需要教练(或老队员)讲课? 四、学校不重视怎么办?
2018/11/6
18
九、特别说明



别相信那些“让我进队,我会好好练!”的同学; 别迷信普通的“NOIP”选手; 所有别人的帮助都是有限的; 任何学校和个人的成功都来之不易; 没有所谓的秘诀,有也是“葵花宝典”;

与人为善,不要好好先生 激情四溢,不要啦啦队长 善于学习,不要投机取巧 耐力长久,不要昏昏度日 定位准确,不在一城得失 热爱生活,ACM不是全部
2018/11/6
14
五、我眼中的ACM好教练

热爱ACM(真的热爱,才有感染力,) 良好心态(生活压力、发展压力) 慧眼伯乐(有潜力的,未必成绩好) 心理专家(安慰、鼓励、痛骂) 组织部长(发挥每个队的最大能量) 后勤部长(安全、经济、开心)
2018/11/6 9
第二部分
普通院校的竞赛建议
2018/11/6
10
一、何谓“普通院校”?

非“985”的普通本科院校 普通院校的特点:

杭电ACM试题详细分类,杭电oj详细分类,hdu详细分类,详细,ACM

杭电ACM试题详细分类,杭电oj详细分类,hdu详细分类,详细,ACM
数论
1164 1211 1215 1222 1286 1299
计算几何
1086 1115 1147
贪心
1009 1052 1055 1232 1272
线段树,离散化
1199 1255
图论 最短路相关的问题
1142 1162 1217 1301
二分图问题
1054 1068 1150 1151 1281
杭电ACM试题分类 枚举
1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 1202 1205 1209 1212(大数取模) 1216(链表)1218 1219 1225 1228 1229 1230 1234 1235 1236 1237 1239 1250 1256 1259 1262 1263 1265 1266 1276 1279 1282 1283 1287 1296 1302 1303 1304 1305 1306 1309 1311 1314
2549、2550、2551、2552、2555、2560、2561、2562、2566、2567、 2568、2700、2710、
DP:1003、10240、1029、1069、1074、1087、1114、1159、1160、
1171、1176、1203、1231、1257、1260、1284、1421、1789、1978、 2059、2084、2159、2191、2544、2571、2602、2709、

杭州电子科技大学acm答案

杭州电子科技大学acm答案

杭州电子科技大学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)

ACM入门十题(杭电oj)

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");}}。

杭电ACM博弈题合集

杭电ACM博弈题合集

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博弈题合集

杭电ACM博弈题合集

杭电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博弈,直接异或即可。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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。

相关文档
最新文档