POJ 1006 - Biorhythms (中国剩余定理)
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
Description
Input
当p = e = i = d = -1时,输入数据结束。
Output
采用以下格式:
Case 1: the next triple peak occurs in 1234 days.
注意:即使结果是1天,也使用复数形式“days”。
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.
Hint
Translator
#include <iostream>
#include <cstdio>
using namespace std;
#define mod 21252
int exgcd(int a,int b,int &x,int &y) //计算扩展欧几里得
{
if(b==) {x=;y=;return a;}
int d=exgcd(b,a%b,y,x); y-=a/b*x;
return d;
}
int inv(int a,int n) //计算逆元
{
int d,x,y;
d=exgcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
}
int datain[]={,,};
int dataout[];
void cal() //计算中国剩余定理
{
int ans=;
for(int i=;i<;i++)
ans*=datain[i];
for(int i=;i<;i++)
{
ans/=datain[i];
dataout[i]=inv(ans,datain[i])*ans; //记得结果算出来
ans*=datain[i]; //记得乘回来
}
}
int main()
{
cal();
//for(int i=0;i<3;i++)
// cout<<dataout[i]<<endl;
int p,e,i,d,cas=,ans;
while(cin>>p>>e>>i>>d)
{
if(p==-&&e==-&&i==-&&d==-)
break;
ans=(dataout[]*p+dataout[]*e+dataout[]*i-d+mod)%mod;
if(!ans) ans=mod;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,ans);
}
return ;
}
代码二:
#include <iostream>
#include <cstdio>
using namespace std;
#define mod 21252
int main()
{
int p,e,i,d,cas=,ans;
while(cin>>p>>e>>i>>d)
{
if(p==-&&e==-&&i==-&&d==-)
break;
ans=(*p+*e+*i-d+mod)%mod;
if(!ans) ans=mod;
printf("Case %d: the next triple peak occurs in %d days.\n",cas++,ans);
}
return ;
}
POJ 1006 - Biorhythms (中国剩余定理)的更多相关文章
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- PKU POJ 1006 Biorhythms (中国剩余定理)
中国剩余定理 x = ai (mod mi) ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk 其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st M ...
- POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)
POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- poj 1006 Biorhythms (中国剩余定理模板)
http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- POJ 1006 Biorhythms (中国剩余定理)
在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...
- 中国剩余定理 POJ 1006 Biorhythms
题目传送门 题意:POJ有中文题面 分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板 代码: /********* ...
随机推荐
- BZOJ-1880 Elaxia的路线 SPFA+枚举
1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 921 Solved: 354 [Submit][Sta ...
- Bzoj 1336&1337 Alien最小圆覆盖
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Submit: 1473 ...
- LFI、RFI、PHP封装协议安全问题学习
本文希望分享一些本地文件包含.远程文件包含.PHP的封装协议(伪协议)中可能包含的漏洞 相关学习资料 http://www.ibm.com/developerworks/cn/java/j-lo-lo ...
- C#通过编程方式实现Ping
代码是照着书敲的,贴出来方便平时参考 using System; using System.Collections.Generic; using System.Linq; using System.T ...
- P、NP、NPC、NP-Hard问题
转自:http://www.matrix67.com/blog/archives/105 总结 P:能用多项式时间求解的问题NP:能用多项式时间验证的问题(但不知道能不能用多项式时间求解).存在不属于 ...
- php多态设计
原文:http://www.cnblogs.com/tecs27/archive/2012/03/13/2394028.html 多态性是指相同的操作或函数.过程可作用于多种类型的对象上并获得不同的结 ...
- Mvc3提交表格验证(转载)
Model层:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System ...
- 字符串模拟赛T3
只看我的做法就够了 #include<iostream> #include<cstdio> #include<string> #include<cstring ...
- Robot Motion(imitate)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11065 Accepted: 5378 Des ...
- 还是畅通工程(MST)
还是畅通工程 Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...