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-1625 宝石手镯 01背包(傻逼题)
傻逼题,懒得打,复制蛋蛋的.. 1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1076 Solved: ...
- 基于SVD的推荐算法
首先每行减去每列的均值,然后svd分解,得到USV,然后US代表用户矩阵u,SV代表项目矩阵v,那么预测评分为用户均值加上uv. 降维方法扩展性好,不过降维导致信息损失,而且与数据及相关,高维情况下效 ...
- 【poj1090】 Chain
http://poj.org/problem?id=1090 (题目链接) 题意 给出九连环的初始状态,要求将环全部取下需要走多少步. Solution 格雷码:神犇博客 当然递推也可以做. 代码 / ...
- 网页设计师常用的PHOTOSHOP插件
Photoshop是网页设计师常用的一个非常重要而强大的工具,可以让网页设计师的工作高效便捷的进行,也为设计师们的天马行空提供了实际技术实现.一般我们的网页设计师设计完成后,需要将其转换制作成网页形式 ...
- POJ3744Scout YYF I(求概率 + 矩阵快速幂)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6757 Accepted: 1960 Descr ...
- linux source与 . 命令
source命令用法:source FileName作用:在当前bash环境下读取并执行FileName中的命令.注:该命令通常用命令“.”来替代.如:source .bash_rc 与 . .bas ...
- dedecms升级后报错
DedeCMS Error: (PHP 5.3 and above) Please set 'request_order' ini value to include C,G and P (recomm ...
- IOC和AOP的基础原理
IoC(Inversion of Control)就是由容器控制程序之间的关系,而非传统实现中,由程序代码直接操控.这也就是所谓“控制反转”的概念所在.控制权由应用代码中转到了外部容器,控制权的转移是 ...
- java笔记--关于线程死锁
关于线程死锁 什么是死锁: 在编写多线程的时候,必须要注意资源的使用问题,如果两个或多个线程分别拥有不同的资源, 而同时又需要对方释放资源才能继续运行时,就会发生死锁. 简单来说:死锁就是当一个或多个 ...
- change column to bigint
今天存储数据的时候报错,发现是3435065640超出了常规int的存储长度, RangeError (3435065640 is out of range for ActiveRecord::Typ ...