Poj 1006

就是中国剩余定理的应用……

幸好我学了数学基础

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int p,e,i,d;
 5     int k;
 6     int count=1;
 7     while(cin>>p>>e>>i>>d){
 8         if(p==-1&&e==-1&&i==-1&&d==-1){
 9             break;
10         }
11         k=0;
12         p=p%23;
13         e=e%28;
14         i=i%33;
15         k=(k+(p*5544))%21252;
16         k=(k+(e*14421))%21252;
17         k=(k+(i*1288))%21252;
18         if(k==0){
19             k+=21252;
20         }
21         if(d==k){
22             cout<<"Case "<<count<<": the next triple peak occurs in "<<21252<<" days."<<endl;
23         }
24         else if(k>d){
25             cout<<"Case "<<count<<": the next triple peak occurs in "<<k-d<<" days."<<endl;
26         }
27         else{
28             cout<<"Case "<<count<<": the next triple peak occurs in "<<k-d+21252<<" days."<<endl;
29         }
30         count++;
31     }
32 }
时间: 2024-10-23 20:16:46

Poj 1006的相关文章

POJ - 1006 Biorhythms (中国剩余定理)

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, respec

poj 1006(剩余定理)

生理周期 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 111426   Accepted: 34702 Description 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色.例如,智力周期的高峰,人会思维敏捷,精力容易高度集中.因为三个周期的周长不同,所以通常三个周期的高峰不会落在同一天.对于每个人,我们想知道

poj 1006:Biorhythms(水题,经典题,中国剩余定理)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 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,

POJ 1006 中国剩余定理

[题意]: 给定p,e,i,d,求解 (x + d) % 23 = p (x + d) % 28 = e(x + d) % 33 = i x最小正整数值 [知识点]: 中国剩余定理 [题解]: 典型的 xmodmi = ai模型,其中mi间两两互素.但该题式子较少,也可以直接自己化简带入值. [代码]: 1 #include <map> 2 #include <set> 3 #include <cmath> 4 #include <ctime> 5 #inc

Biorhythms POJ - 1006

Biorhythms POJ - 1006 题意: 求解一元线性同余方程组. 1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 const int maxn=1010; 5 int b[maxn],m[maxn]; 6 int n; 7 void exgcd(int a,int b,int &d,int &x,int &y){ 8 if(!b){d=a;x=1;y=0;} 9

PKU POJ 1006 Biorhythms (中国剩余定理)

中国剩余定理 x = ai (mod mi)  ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk     其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st   Mi*xi + mi*yi = 1 令ei = Mi*xi ,则有: 则e0a0 + e1a1 + e2a2+ - +en-1*an-1是方程一个解 因为n%3=2,n%5=3,n%7=2且3,5,7互质       使5×7被3除余1,用35×2=70:        使3×7被5除余1,用21×1

转载----POJ 1006 中国剩余定理

本文为转载,源地址:   http://blog.csdn.net/dongfengkuayue/article/details/6461298 POJ 1006   Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 78980   Accepted: 23740 Description Some people believe that there are three cycles in a perso

中国剩余定理小结 (互质,非互质) (poj 1006,hdu 3579)

先证明下中国剩余定理 条件: x%m_1=a_1 x%m_2=a_2 ... x%m_n=a_n m_1,m_2,...,m_n两两互质 证明: 设M=m_1*m_2*m_3*...*m_n M_i=M/m_i 因为gcd(M_i,m_i)=1,所以M_ix+m_iy=1 (t_i*M_i)%m_i=1 //由Ext_gcd(M_i,m_i,x,y)求出,t_i=x 方程组的解:x=a_1*t_1*M_1+...+a_n*t_n*M_n 题目:poj 1006 http://poj.org/pr

生理周期,POJ(1006)

题目链接:http://poj.org/problem?id=1006 解题报告: 1.枚举天数的时候可以根据前面的结果直接跳过一些错误的答案. ///三个周期是23,28,33, #include <stdio.h> int main() { int p,e,i,d,Case=1; while(scanf("%d%d%d%d",&p,&e,&i,&d),p!=-1) { int t1=p%23,t2=e%28,t3=i%33;///三个周期

poj 1006 生理周期

题目链接:http://poj.org/problem?id=1006 题意:中文题. 中国剩余定理: 1 #include <cstdio> 2 #include <cmath> 3 4 using namespace std; 5 6 int main() 7 { 8 int p,e,i,d; 9 int Case=1; 10 int lcd = 21252; 11 while(scanf("%d%d%d%d",&p,&e,&i,&a