Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 125197 |
|
Accepted: 39528 |
Description
Humans are born with three cycles of physical, emotional and intellectual cycles, with periods of 23 days, 28 days and 33 days. One day in each cycle is a peak. At the peak of the day, people will do well in the corresponding aspects. For example, the peak of the intellectual cycle, people will be quick thinking, energy is easy to highly concentrated. Because the circumference of the three cycles is different, the peak of three cycles usually does not fall on the same day. For everyone, we want to know when three peaks fall on the same day. For each cycle, we will give the number of days from the first day of the current year to the peak (not necessarily the time of the first peak). Your task is to give a number of days from the first day of the year, and the output starts from a given time (excluding a given time) the next three peaks fall on the same date (the number of days from a given time). For example: Given a time of 10, the next occurrence of three peaks on the same day is 12, then output 2 (note that this is not 3).
Input
enter four integers: p, E, I, and D. P, E, I, respectively, indicate the time at which the physical, emotional and intellectual peaks appear (the time is calculated from the first day of the year). D is the given time, which may be less than P, E, or I. All given times are non-negative and less than 365, and the time required is less than 21252.
When p = e = i = d =-1, the input data ends.
Output
from a given time, the next three peaks of the same day (the number of days from a given time).
The following format is used:
Case 1:the Next triple peak occurs in 1234 days.
Note: Even if the result is 1 days, also use the plural form "day".
Sample Input
0 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 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
East Central North America 1999
Translator
Beijing University Program Design Internship, Xie Di
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cmath>5#include <algorithm>6#include <cstring>7 using namespacestd;8 inta[Ten],m[Ten],tot,now,m;9InlinevoidEXGCD (intAintBint&d,int&x,int&y) {Ten if(b==0){ Onex=1; y=0; D=A; A return ; - } -EXGCD (B,A%B,D,Y,X); Y-=x* (A/b); the } -InlineintChina (intR) { -m=1; - intmi,d,x0=0, y0=0, ans=0; + for(intI=1; i<=r;i++) m*=M[i]; - for(intI=1; i<=r;i++){ +mi=m/M[i]; AEXGCD (MI,M[I],D,X0,Y0);//x0 is the multiplication inverse of Mi atAns= (Ans+mi*x0*a[i])%M; - } -ans= (ans+m)%M; - returnans; - } - intMain () { inm[1]= at; m[2]= -; m[3]= -; - while(SCANF ("%d%d%d%d", &a[1],&a[2],&a[3],&now) &&a[1]!=-1){ totot++; + if(a[1]==a[2]&&a[2]==a[3]&&a[3]==0){ -printf"Case %d:the Next triple peak occurs in%d days.\n"Tot21252-Now ); the Continue; * } $ intAns=china (3);Panax Notoginseng while(Ans<=now) ans+=M; -printf"Case %d:the Next triple peak occurs in%d days.\n", tot,ans-Now ); the } + return 0; A}
POJ 1006 Biorhythms