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),套用中国剩余定理模板 代码: /********* ...
随机推荐
- FatMouse的交易问题
想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...
- 在myeclipse10.7.1中写代码有很多红x
代码没问题,但是很多代码前都有红x.在doc中执行都没有问题 jdk版本不对应 //第一步:菜单栏Window--Preferences--Java--Installed JREs--右边Add ...
- Jquery插件easyUi表单验证提交
<form id="myForm" method="post"> <table align="center" style= ...
- 微型 ORM-FluentData 温故知新系列
http://www.cnblogs.com/_popc/archive/2012/12/26/2834726.html 引言:FluentData 是微型 ORM(micro-ORM)家族的一名新成 ...
- 锋利的jQuery-3--css("height")和.height()的区别
$("p").css("height") : 获取的高度值与样式的设置有关,可能会得到“auto”, 也可能是字符串“10px”之类的.设置值时如果是数值形式默 ...
- python多线程备份MYSQL数据库并删除旧的备份。
#!/usr/bin/python # -*- coding=utf-8 -*- import time import os import datetime import threading from ...
- WCF 客户端解决大数据量传输配置
1. 服务端返回数据给客户端报错 在客户端配置文件中,主要是配置maxReceivedMessageSize <system.serviceModel> <bindings> ...
- Object、Function、String、Array原生对象扩展方法
JavaScript原生对象的api有些情况下使用并不方便,考虑扩展基于Object.Function.String.Array扩展,参考了prototype.js的部分实现,做了提取和修改,分享下: ...
- 微信用户量破6.5亿 首超移动QQ
腾讯控股有限公司昨日公布了微信和WeChat合并月活跃用户量达到6.5亿,同比再涨39%.QQ在移动智能终端月活为6.39亿,同比增长18%,尽管势头也不错,但这是第一次,微信干掉了移动QQ! 201 ...
- "微信全球商业创新大赛-创意中国2015"国际MBA商业挑战赛开启
微信商业化进程一直在摸索中前进,从未间断.近日由中欧国际工商学院与腾讯(Tencent)共同发起举办“微信全球商业创新大赛 - 创意中国2015”(We Win with WeChat - INNOV ...