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),套用中国剩余定理模板 代码: /********* ...
随机推荐
- ELF(Executable and Linkable Format)
目录 . 引言 . ELF文件格式 . ELF格式分析工具 0. 引言 0x1: ELF文件类型 ELF文件标准里把系统中采用ELF格式的文件归为以下几类 . 可重定位文件(Relocatable F ...
- hihocoder #1285 智力竞赛
传送门 总结: 1.仔细读题 2.仔细分析复杂度 3.不要想当然,乱下结论 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi.小Ho还有被小Hi强拉来的小Z,准备组队 ...
- aapt aidl
AIDL:Android Interface Definition Language,即Android接口定义语言 aapt即Android Asset Packaging Tool,在SDK的bui ...
- asp.net修改web.config文件
private void UpdateConfigFile() { var cfg = System.Web.Configuration.WebConfigurationManager.OpenWeb ...
- 文件系统:drbd主备服务器文件同步
一. DRBD介绍 DRBD是一种块设备,可以被用于高可用(HA)之中.它类似于一个网络RAID-1功能.当你将数据写入本地 文件系统时,数据还将会被发送到网络中另一台主机上.以相同的形式记录在一个文 ...
- struts2 访问国际化资源 <s:text>作为属性
保留全局级国际化信息资源文件.并在message.properteis中增加一个带有参数的国际化信息. labela = labela in zh_CN labelb = labelb,{0} < ...
- 错误 1 未知的服务器标记“asp:ScriptManager”。
如题 ... 解决方案 :将 <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=ne ...
- thinkphp中page方法
page方法也是模型的连贯操作方法之一,是完全为分页查询而诞生的一个人性化操作方法. 用法 我们在前面已经了解了关于limit方法用于分页查询的情况,而page方法则是更人性化的进行分页查询的方法,例 ...
- HDU 4857 Couple doubi(找循环节)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4861 解题报告:桌子上有k个球 ,第i个球的价值wi = 1^i+2^i+...+(p-1)^i (m ...
- iOS UILabel圆角
对于UIView 直接设置 uiview.layer.cornerRadius = 5 就可以有圆角了 但是对于UILabel则不然, 要多设置一个uilabel.clipsToBounds = YE ...