标签:esc string 0ms cas 复数 return output 输出 field
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 138291 | Accepted: 44300 |
Description
Input
Output
Sample Input
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in 21252 days.
Case 2: the next triple peak occurs in 21152 days.
Case 3: the next triple peak occurs in 19575 days.
Case 4: the next triple peak occurs in 16994 days.
Case 5: the next triple peak occurs in 8910 days.
Case 6: the next triple peak occurs in 10789 days.
Source
Translator
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int M,s,tot,ans,m[10],a[10]; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1; ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f; } int exgcd(int a,int b,int &x,int &y) { if(b==0) { x=1,y=0; return a; } int r=exgcd(b,a%b,x,y),tmp; tmp=x,x=y,y=tmp-a/b*y; return r; } int crt() { int mi,sum=0,x,y; for(int i=1;i<=3;i++) { mi=M/m[i]; exgcd(mi,m[i],x,y); sum=(sum+x%M*mi%M*a[i]%M)%M; } if(sum<0) sum+=M; return sum; } int main() { m[1]=23,m[2]=28,m[3]=33;M=m[1]*m[2]*m[3]; while(1) { for(int i=1;i<=3;i++) a[i]=read(); s=read(); if(a[1]==-1&&a[2]==-1&&a[3]==-1&&s==-1) break; ans=crt()-s; while(ans<=0) ans+=M; printf("Case %d: the next triple peak occurs in %d days.\n",++tot,ans); } return 0; }
标签:esc string 0ms cas 复数 return output 输出 field
原文地址:http://www.cnblogs.com/z360/p/7348839.html