很多以前写的丑代码
1000 - Greetings from LightOJ
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&a,&b); printf("Case %d: %d\n",Case,a+b); } return 0; }
1001 - Opposite Task
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int n,t; int c[21]= {0}; for(int i=11; i<=20; i++) c[i]=i-10; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d %d\n",c[n],n-c[n]); if(c[n]<10&&(n-c[n])>0)//相同输入输出不同 c[n]++; } return 0; }
1006 - Hex-a-bonacci
理解代码段的作用然后优化
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> long long a, b, c, d, e, f; long long x[10001]; long long fn(long long n) { int i,j; for(i=0; i<n; i++) x[i]=0; x[n]=1; for(i=n; i>=6; i--) { x[i]%=10000007; for(j=i-6; j<i; j++) x[j]+=x[i]; } return a*x[0]% 10000007 +b*x[1]% 10000007 +c*x[2]% 10000007 +d*x[3]% 10000007 +e*x[4]% 10000007 +f*x[5]% 10000007; } int main() { long long n, caseno = 0, cases; scanf("%lld", &cases); while( cases-- ) { scanf("%lld %lld %lld %lld %lld %lld %lld", &a, &b, &c, &d, &e, &f, &n); printf("Case %lld: %lld\n", ++caseno, fn(n) % 10000007); } return 0; }
1008 - Fibsieve`s Fantabulous Birthday
找规律
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { long long Case=0,t,n,i,x,y; scanf("%lld",&t); while(Case++,t--) { scanf("%lld",&n); i=sqrt(n-1); n-=i*i; if(i%2==1) { if(n>=i+1) { n-=i+1; x=i+1,y=i+1; y-=n; } else { x=n,y=i+1; } } else { if(n>=i+1) { n-=i+1; x=i+1,y=i+1; x-=n; } else { x=i+1,y=n; } } printf("Case %lld: %lld %lld\n",Case,x,y); } return 0; }
1010 - Knights in Chessboard
在棋盘中放knights可以放多少个,找规律
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int m,n,t,Case=0,ans,mod,temp; scanf("%d",&t); while(Case++,t--) { scanf("%d%d",&m,&n); if(n==1||m==1) ans=m*n; else if(n==2||m==2) { ans=m*n/2; mod=ans%4; switch(mod) { case 0: temp=ans; break; case 1: temp=ans/4*4+2; break; case 2: temp=ans/4*4+4; break; case 3: temp=ans/4*4+4; break; default: break; } ans=temp; } else ans=(m*n+1)/2; printf("Case %d: %d\n",Case,ans); } return 0; }
1015 - Brush (I)
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int n,t,Case=0,i; long long sum; int a[1000]; scanf("%d",&t); while(Case++,t--) { scanf("%d",&n); sum=0; for(i=0; i<n; i++) { scanf("%d",&a[i]); if(a[i]>0) sum+=a[i]; } printf("Case %d: %lld\n",Case,sum); } }
1022 - Circle in Square
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0; double s,r; scanf("%d",&t); while(Case++,t--) { scanf("%lf",&r); s=(4-acos(-1.0))*r*r; printf("Case %d: %.2f\n",Case,s); } return 0; }
1042 - Secret Origins
求一个数和n在二进制中“1”的个数相同,且恰好比n大
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0,i,len,b,e; long long n; int a[100]; scanf("%d",&t); while(Case++,t--) { scanf("%lld",&n); len=i=0; memset(a,0,sizeof(a)); while(n!=0) { a[i++]=n%2; n/=2; } len=i; for(i=0; i<len; i++) if(a[i]==1) break; b=i; for(i++; i<=len; i++) if(a[i]!=1) { a[i]=1; a[i-1]=0; break; } e=i-2; for(i=b; i<=e; i++) a[i]=0; for(i=0; i<=e-b; i++) a[i]=1; for(i=len; i>=0; i--) n=n*2+a[i]; printf("Case %d: %lld\n",Case,n); } return 0; }
1045 - Digits of Factorial
利用log函数,ans=log(f[n])/log(base),利用log函数也不怕溢出
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> double f[1000001]; int main(void) { int t,n,base,Case=0,i; double digit; scanf("%d",&t); for(i=1; i<=1000000; i++) f[i]=f[i-1]+log((double)i); while(Case++,t--) { scanf("%d%d",&n,&base); if(n>0) digit=f[n]/log(1.0*base); else digit=1.0; digit=ceil(digit); printf("Case %d: %0.f\n",Case,digit); } return 0; }
1053 - Higher Math
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int cmp(const void *a,const void *b) { return *(double *)a>*(double *)b?1:-1; } int main(void) { double a[3]; const double eps=0.000001; int t,Case=0; scanf("%d",&t); while(Case++,t--) { scanf("%lf%lf%lf",&a[0],&a[1],&a[2]); qsort(a,3,sizeof(a[0]),cmp); if(fabs(pow(a[0],2)+pow(a[1],2)-pow(a[2],2))<eps) printf("Case %d: yes\n",Case); else printf("Case %d: no\n",Case); } return 0; }
1069 - Lift
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int n,c,t,Case=0; scanf("%d",&t); while(Case++,t--) { scanf("%d%d",&c,&n); if(n>c) printf("Case %d: %d\n",Case,4*n+19); else printf("Case %d: %d\n",Case,4*(c+c-n)+19); } return 0; }
1072 - Calm Down
初中平面几何
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0,i; double R,n,r,sita,a; int count; long long b; int dec[10]; scanf("%d",&t); while(Case++,t--) { scanf("%lf%lf",&R,&n); sita=acos(-1)/n; r=sin(sita)/(sin(sita)+1)*R; b=pow(10,10)*modf(r+0.00000000005,&a); count=0; while(count<10&&b%10==0) { b/=10; count++; } for(i=0; i<10-count; i++) { dec[i]=b%10; b/=10; } if(count!=10) { printf("Case %d: %0.f.",Case,a); for(i=10-count-1; i>=0; i--) printf("%d",dec[i]); puts(""); } else printf("Case %d: %0.f\n",Case,a); } return 0; }
1107 - How Cow
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int x,x1,x2,y,y1,y2,t,Case=0,n; scanf("%d",&t); while(Case++,t--) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); scanf("%d",&n); printf("Case %d:\n",Case); while(n--) { scanf("%d%d",&x,&y); if(x>x1&&x<x2&&y>y1&&y<y2) printf("Yes\n"); else printf("No\n"); } } return 0; }
1109 - False Ordering
按所给条件排个序
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> struct node { int val; int div; } a[1001]; int cmp(const void *a,const void *b) { if((*(struct node*)a).div!=(*(struct node*)b).div) return (*(struct node*)a).div-(*(struct node*)b).div; else return (*(struct node*)b).val-(*(struct node*)a).val; } int main(void) { int t,Case=0,count,i,j,n; scanf("%d",&t); for(i=1; i<=1000; i++) { a[i].val=i; for(j=1,count=0; j<=i; j++) { if(i%j==0) count++; } a[i].div=count; } qsort(a+1,1000,sizeof(a[1]),cmp); while(Case++,t--) { scanf("%d",&n); printf("Case %d: %d\n",Case,a[n].val); } return 0; }
1113 - Discover the Web
用c++STL的stack可以水过
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { char backward_stack[105][66],forward_stack[105][66]; char current[66],s[66]; int t,Case=0,bi,fi; scanf("%d\n",&t); while(Case++,t--) { memset(backward_stack,'\0',sizeof(backward_stack)); memset(forward_stack,'\0',sizeof(forward_stack)); strcpy(current,"http://www.lightoj.com/"); bi=fi=0; printf("Case %d:\n",Case); while(1) { gets(s); if(s[0]=='Q') break; else if(s[0]=='V') { strcpy(backward_stack[bi++],current); sscanf(s,"%*s%s",current); memset(forward_stack,'\0',sizeof(forward_stack)); fi=0; } else if(s[0]=='B') { if(bi>0) { strcpy(forward_stack[fi++],current); strcpy(current,backward_stack[--bi]); strcpy(backward_stack[bi],""); } else { printf("Ignored\n"); continue; } } else if(s[0]=='F') { if(fi>0) { strcpy(backward_stack[bi++],current); strcpy(current,forward_stack[--fi]); strcpy(forward_stack[fi],""); } else { printf("Ignored\n"); continue; } } printf("%s\n",current); } } return 0; }
1116 - Ekka Dokka
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0,i,index; long long w,n,m; scanf("%d",&t); while(Case++,t--) { scanf("%lld",&w); index=0; for(i=1; i<64; i++) { m=pow(2,i); n=w/m; if(n*m==w&&n%2==1) { index=1; break; } }//上面写丑了 应该是while(n&1==0)n/=2,m*=2; if(index==1) printf("Case %d: %lld %lld\n",Case,n,m); else printf("Case %d: Impossible\n",Case); } return 0; }
1133 - Array Simulation
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> void swap(int *a,int *b) { int t=*a; *a=*b; *b=t; } int main(void) { int Case=0,t,n,m,a[100],d; char c,e; int i,j,x,y; scanf("%d",&t); while(Case++,t--) { scanf("%d%d",&n,&m); for(i=0; i<n; i++) scanf("%d",&a[i]); for(i=0; i<m; i++) { scanf(" %c",&c); switch(c) { case 'S': scanf("%d",&d); for(j=0; j<n; j++) a[j]+=d; break; case 'M': scanf("%d",&d); for(j=0; j<n; j++) a[j]*=d; break; case 'D': scanf("%d",&d); for(j=0; j<n; j++) a[j]/=d; break; case 'P': scanf("%d%d",&x,&y); swap(&a[x],&a[y]); break; case 'R': for(j=0; j<n/2; j++) swap(&a[j],&a[n-1-j]); break; default: break; } } printf("Case %d:\n",Case); printf("%d",a[0]); for(i=1; i<n; i++) printf(" %d",a[i]); puts(""); } return 0; }
1136 - Division by 3
找规律
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,a,b,ans,mod,Case=0; scanf("%d",&t); while(Case++,t--) { scanf("%d%d",&a,&b); ans=b/3*2; mod=b%3; if(mod==2) ans+=1; a-=1; mod=a%3; ans-=a/3*2; if(mod==2) ans-=1; printf("Case %d: %d\n",Case,ans); } return 0; }
1182 - Parity
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0,n,count; scanf("%d",&t); while(Case++,t--) { scanf("%d",&n); count=0; while(n) { count+=n&1; n=n>>1; } if(count&1) printf("Case %d: odd\n",Case); else printf("Case %d: even\n",Case); } return 0; } //可以将状态压缩在末尾,再&1
1189 - Sum of Factorials
因为阶乘递增很快,前面全部加起来都没下一个大,可以直接贪心
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { long long fac[21]; int i,j; fac[0]=fac[1]=1; for(i=2; i<21; i++) { fac[i]=fac[i-1]*i; } int t,Case=0; long long n; scanf("%d",&t); while(Case++,t--) { scanf("%lld",&n); int a[21]; j=0; for(i=20; i>=0; i--) if(n-fac[i]>=0) { n-=fac[i]; a[j++]=i; } if(n==0) { printf("Case %d: %d!",Case,a[j-1]); for(i=j-2; i>=0; i--) printf("+%d!",a[i]); puts(""); } else { printf("Case %d: impossible\n",Case); } } return 0; }
1202 - Bishops
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int x1,x2,y1,y2,t,Case=0; scanf("%d",&t); while(Case++,t--) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if(abs(x1-x2+y1-y2)%2==0) { if(abs(x1-x2)==abs(y1-y2)) printf("Case %d: 1\n",Case); else printf("Case %d: 2\n",Case); } else printf("Case %d: impossible\n",Case); } return 0; }
1211 - Intersection of Cubes
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int min(int a,int b) { return a<b?a:b; } int max(int a,int b) { return a>b?a:b; } int main(void) { int t,Case=0,n,x1,x2,y1,y2,z1,z2,minx,miny,minz,maxx,maxy,maxz; scanf("%d",&t); while(Case++,t--) { scanf("%d",&n); minx=miny=minz=0; maxx=maxy=maxz=1001; while(n--) { scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2); minx=max(x1,minx); miny=max(y1,miny); minz=max(z1,minz); maxx=min(x2,maxx); maxy=min(y2,maxy); maxz=min(z2,maxz); } if(minx<maxx&&miny<maxy&&minz<maxz) printf("Case %d: %d\n",Case,(maxx-minx)*(maxy-miny)*(maxz-minz)); else printf("Case %d: 0\n",Case); } return 0; }
1212 - Double Ended Queue
#include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; char s[10]; int len,n; deque<int> dq; scanf("%d",&t); while(t--) { scanf("%d%d",&len,&n); printf("Case %d:\n",++Case); while(n--) { scanf("%s",s); if(strcmp(s,"pushLeft")==0) { int e; scanf("%d",&e); if(dq.size()==len) printf("The queue is full\n"); else { dq.push_front(e); printf("Pushed in left: %d\n",e); } } else if(strcmp(s,"pushRight")==0) { int e; scanf("%d",&e); if(dq.size()==len) printf("The queue is full\n"); else { dq.push_back(e); printf("Pushed in right: %d\n",e); } } else if(strcmp(s,"popLeft")==0) { if(dq.empty()) printf("The queue is empty\n"); else { printf("Popped from left: %d\n",dq.front()); dq.pop_front(); } } else { if(dq.empty()) printf("The queue is empty\n"); else { printf("Popped from right: %d\n",dq.back()); dq.pop_back(); } } } dq.clear(); } return 0; }
1214 - Large Division
一遍读一遍mod
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0; char a[220]; long long b,ans; int i,len; scanf("%d",&t); while(Case++,t--) { scanf("%s%lld",a,&b); len=strlen(a); i=0; ans=0; if(a[0]=='-') i++; for(;i<len;i++) { ans=(ans*10+a[i]-'0')%b; } // printf("ans=%lld\n",ans); if(ans==0) printf("Case %d: divisible\n",Case); else printf("Case %d: not divisible\n",Case); } return 0; }
1216 - Juice in the Glass
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0; double r1,r2,p,h; scanf("%d",&t); while(Case++,t--) { scanf("%lf%lf%lf%lf",&r1,&r2,&h,&p); r1=(r1-r2)*p/h+r2; double s1=r1*r1*acos(-1); double s2=r2*r2*acos(-1); printf("Case %d: %.8f\n",Case,1.0/3.0*p*(s1+sqrt(s1*s2)+s2)); } return 0; }
1225 - Palindromic Numbers (II)
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0; char s[11]; scanf("%d",&t); while(Case++,t--) { scanf("%s",s); int len=strlen(s); int flag=1; for(int i=0; i<len/2; i++) if(s[i]!=s[len-1-i]) { flag=0; break; } if(flag) printf("Case %d: Yes\n",Case); else printf("Case %d: No\n",Case); } return 0; }
1227 - Boiled Eggs
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0; int n,p,q; int a[33]; scanf("%d",&t); while(Case++,t--) { scanf("%d%d%d",&n,&p,&q); for(int i=0; i<n; i++) scanf("%d",&a[i]); int sum=0; int count=0; for(int i=0; i<n&&i<p; i++) { if(sum+a[i]<=q) { sum+=a[i]; count++; } else break; } printf("Case %d: %d\n",Case,count); } return 0; }
1241 - Pinocchio
#include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int t,Case=0; int n,i; int a[11]={2}; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1; i<=n; i++) { scanf("%d",&a[i]); } int count=0; for(i=1; i<=n; i++) { if(a[i]>a[i-1]) count+=(a[i]-a[i-1]-1)/5+1; } printf("Case %d: %d\n",++Case,count); } return 0; }
1249 - Chocolate Thief
#include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n; int l,w,h,vol; char minname[22],maxname[22]; char name[22]; scanf("%d",&t); while(t--) { scanf("%d",&n); int min=1e9; int max=0; for(int i=0;i<n;i++) { scanf("%s%d%d%d",name,&l,&w,&h); vol=l*w*h; if(vol<min) { min=vol; strcpy(minname,name); } if(vol>max) { max=vol; strcpy(maxname,name); } } printf("Case %d: ",++Case); if(max>min) printf("%s took chocolate from %s\n",maxname,minname); else printf("no thief\n"); } return 0; }
1261 - K-SAT Problem
#include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n,m,k,p; int vis[33]; int a[33][33]; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) { for(int j=0; j<k; j++) { scanf("%d",&a[i][j]); } } scanf("%d",&p); int num; for(int i=0; i<p; i++) { scanf("%d",&num); vis[num]=1; } int ok; for(int i=0; i<n; i++) { ok=0; for(int j=0; j<k; j++) { if(a[i][j]<0&&vis[-a[i][j]]==0) { ok=1; break; } if(a[i][j]>0&&vis[a[i][j]]==1) { ok=1; break; } } if(!ok) break; } printf("Case %d: ",++Case); if(!ok) printf("No\n"); else printf("Yes\n"); } return 0; }
1294 - Positive Negative Sign
#include<bits/stdc++.h> using namespace std; int main(void) { long long a,b; int t,Case=0; scanf("%d",&t); while(t--) { cin>>a>>b; printf("Case %d: ",++Case); cout<<a/(2*b)*b*b<<endl; } return 0; }
1305 - Area of a Parallelogram
这里用了个三角形的2倍有向面积
#include<bits/stdc++.h> using namespace std; double s(double xx1,double xx2,double xx3,double yy1,double yy2,double yy3) { return fabs(xx1*yy2+xx2*yy3+xx3*yy1-xx1*yy3-xx2*yy1-xx3*yy2); } int main(void) { double ax,bx,cx,dx,ay,by,cy,dy; int t,Case=0; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&cx,&cy); printf("Case %d: ",++Case); printf("%.0f %.0f %.0f\n",cx+ax-bx,cy+ay-by,s(ax,bx,cx,ay,by,cy)); } return 0; }
1311 - Unlucky Bird
#include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; double v1,v2,v3,a1,a2; double time,d; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf",&v1,&v2,&v3,&a1,&a2); d=v1*v1/2/a1+v2*v2/2/a2; time=max(v1/a1,v2/a2); printf("Case %d: %lf %lf\n",++Case,d,time*v3); } return 0; }
1331 - Agent J
把圆心连起来,求三角形面积再减掉白色部分
#include<bits/stdc++.h> using namespace std; double sita(double a,double b,double c) { return acos((a*a+b*b-c*c)/(2*a*b)); } double tris(double a,double b,double c) { double p=(a+b+c)/2; return sqrt(p*(p-a)*(p-b)*(p-c)); } int main(void) { double r1,r2,r3; double a,b,c; int t,Case=0; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf",&r1,&r2,&r3); a=r1+r2; b=r2+r3; c=r3+r1; double ans=tris(a,b,c); ans-=sita(a,c,b)/2*r1*r1; ans-=sita(a,b,c)/2*r2*r2; ans-=sita(c,b,a)/2*r3*r3; printf("Case %d: %.10lf\n",++Case,ans); } return 0; }
1338 - Hidden Secret!
#include<bits/stdc++.h> using namespace std; int _equal(int cnt1[],int cnt2[]) { for(int i=0;i<26;i++) { if(cnt1[i]!=cnt2[i]) return 0; } return 1; } int main(void) { int t,Case=0; char s[110]; int cnt1[30]; int cnt2[30]; scanf("%d ",&t); while(t--) { gets(s); memset(cnt1,0,sizeof(cnt1)); memset(cnt2,0,sizeof(cnt2)); for(int i=0;s[i]!='\0';i++) { if(s[i]>='A'&&s[i]<='Z') s[i]=s[i]+'a'-'A'; if(s[i]>='a'&&s[i]<='z') cnt1[s[i]-'a']++; } gets(s); for(int i=0;s[i]!='\0';i++) { if(s[i]>='A'&&s[i]<='Z') s[i]=s[i]+'a'-'A'; if(s[i]>='a'&&s[i]<='z') cnt2[s[i]-'a']++; } printf("Case %d: ",++Case); if(_equal(cnt1,cnt2)) printf("Yes\n"); else printf("No\n"); } return 0; }
1354 - IP Checking
#include<bits/stdc++.h> using namespace std; void change(int &a) { int tmp=a; int x=1; a=0; while(tmp) { if(tmp%10) a+=x; x<<=1; tmp/=10; } } int main(void) { int t,Case=0; int a,b,c,d; int aa,bb,cc,dd; scanf("%d ",&t); while(t--) { scanf("%d.%d.%d.%d",&a,&b,&c,&d); scanf("%d.%d.%d.%d",&aa,&bb,&cc,&dd); change(aa); change(bb); change(cc); change(dd); printf("Case %d: ",++Case); if(aa==a && bb==b && cc==c && dd==d) printf("Yes\n"); else printf("No\n"); } return 0; }
1387 - Setu
#include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("Case %d:\n",++Case); char s[22]; int sum=0; while(n--) { scanf("%s",s); int k; if(s[0]=='d') sum+=(scanf("%d",&k),k); else printf("%d\n",sum); } } return 0; }
1414 - February 29
#include<bits/stdc++.h> using namespace std; int month(char s[]) { if(!strcmp(s,"January")) return 1; if(!strcmp(s,"February")) return 2; if(!strcmp(s,"March")) return 3; if(!strcmp(s,"April")) return 4; if(!strcmp(s,"May")) return 5; if(!strcmp(s,"June")) return 6; if(!strcmp(s,"July")) return 7; if(!strcmp(s,"August")) return 8; if(!strcmp(s,"September")) return 9; if(!strcmp(s,"October")) return 10; if(!strcmp(s,"November")) return 11; if(!strcmp(s,"December")) return 12; return 0; } int leapyear(int y) { if(y%4==0 && y%100!=0 || y%400==0) return 1; return 0; } int main(void) { int t,Case=0; int y1,y2,m1,m2,d1,d2; char s1[22],s2[22]; scanf("%d ",&t); while(t--) { scanf("%s %d, %d",s1,&d1,&y1); scanf("%s %d, %d",s2,&d2,&y2); m1=month(s1); m2=month(s2); int ans=(y2-y1)/400*97; y1=y1%400; y2=y2%400; if(y1>y2) y2+=400; for(int i=y1; i<=y2; i++) if(leapyear(i)) ans++; if(leapyear(y1)&&m1>=3) ans--; if(leapyear(y2)) { if(m2==1) ans--; else if(m2==2&&d2<=28) ans--; } printf("Case %d: %d\n",++Case,ans); } return 0; }
1433 - Minimum Arc Distance
#include<bits/stdc++.h> using namespace std; double xo,xa,xb,yo,ya,yb; double d(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double s() { double a=d(xo,yo,xa,ya); double c=d(xa,ya,xb,yb); return acos(1.0-c*c/2/a/a)*a; } int main(void) { int t,Case=0; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf",&xo,&yo,&xa,&ya,&xb,&yb); printf("Case %d: %f\n",++Case,s()); } return 0; }