标签:输入数据 math 知识 时间 ssi source return turn next
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 138947 | Accepted: 44597 |
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 <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; const int mod = 21252; int d,a[4]; int cnt = 0,ans,M; int m[4] = {0,23,28,33}; void exgcd(int a,int b,int &x,int &y) { if (!b) { x = 1; y = 0; return; } exgcd(b,a % b,x,y); int t = x; x = y; y = t - (a / b) * y; return; } void china() { ans = 0,M = 1; for (int i = 1; i <= 3; i++) M *= m[i]; for (int i = 1; i <= 3; i++) { int mi = M / m[i]; int x,y; exgcd(mi,m[i],x,y); ans = (ans + a[i] * mi * x) % M; } if (ans < 0) ans += M; } int main() { while (scanf("%d%d%d%d",&a[1],&a[2],&a[3],&d) && a[1] >= 0 && a[2] >= 0 && a[3] >= 0 && d >= 0) { cnt++; china(); if (ans <= d) ans += mod; ans -= d; printf("Case %d: the next triple peak occurs in %d days.\n",cnt,ans); } return 0; }
标签:输入数据 math 知识 时间 ssi source return turn next
原文地址:http://www.cnblogs.com/zbtrs/p/7496457.html