Biorhythms
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 31 Accepted Submission(s) : 17
Problem Description
Some people believe that there are three cycles in a person’s life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier.
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.
Output
For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form: Case 1: the next triple peak occurs in 1234 days. Use the plural form ``days’’ even if the answer is 1.
Sample Input
1
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
https://www.cnblogs.com/yym2013/p/3768786.html
题意:三个高峰周期分别为23,28,33,给你一个d这一年过了几天,p,e,i表示前一次三个高峰距d过了多少天,求三个高峰在d之后的第几天出现
输入的格式巨坑》》》
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
ll p,e,i,d;
ll tt=0;
int n;
scanf("%d",&n);
while(n--)
{
while(cin>>p>>e>>i>>d)
{
if(p==-1&&e==-1&&i==-1&&d==-1) break;
ll ans=(5544*p+14421*e+1288*i)%21252;
if(ans<=d)
{
ans+=21252;
}
printf("Case %lld: the next triple peak occurs in %lld days.\n",++tt,ans-d);
}
}
}
前面的系数的求法》》》
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int a=28*33,b=23*33,c=23*28;
for(int i=1;;i++)
{
if((a*i)%23==1){
a*=i;
break;
}
}
for(int i=1;;i++)
{
if((b*i)%28==1){
b*=i;
break;
}
}
for(int i=1;;i++)
{
if((c*i)%33==1){
c*=i;
break;
}
}
int base=23*28*33;
int mm,tt=0;
scanf("%d",&mm);
while(mm--)
{
int p,e,i,d;
while(cin>>p>>e>>i>>d)
{
if(p==-1&&e==-1&&i==-1&&d==-1) break;
int ans=(a*p+b*e+i*c)%base;
if(ans<=d) ans+=base;
printf("Case %d: the next triple peak occurs in %d days.\n",++tt,ans-d);
}
}
}
拓展欧几里得
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int m[5],a[5],M;
int exgcd(int a,int b,int &x,int &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
int ans=exgcd(b,a%b,x,y);
int tt=x;
x=y;
y=tt-a/b*y;
return ans;
}
int china(int n)
{
M=1;
for(int i=1;i<=n;i++)
{
M*=m[i];
}
int Mi,x,y,ans=0;
for(int i=1;i<=n;i++)
{
Mi=M/m[i];
int g=exgcd(Mi,m[i],x,y);
ans=(ans+x*Mi*a[i])%M;
}
return ans;
}
int main()
{
int mm,tt=0;
scanf("%d",&mm);
while(mm--)
{
int p,e,i,d;
while(cin>>p>>e>>i>>d)
{
if(p==-1&&e==-1&&i==-1&&d==-1) break;
m[1]=23,m[2]=28,m[3]=33;//余数
a[1]=p,a[2]=e,a[3]=i;
int ans=china(3);
while(ans<=d) ans+=M;
printf("Case %d: the next triple peak occurs in %d days.\n",++tt,ans-d);
}
}
}