POJ1006 - Biorhythms(中国剩余定理)
题目大意
略。。。有中文。。。
题解
就是解同余方程组
x≡(p-d)(mod 23)
x≡(e-d)(mod 28)
x≡(i-d)(mod 33)
最简单的中国剩余定理应用。。。。
代码:
#include<iostream>
#include<cstdio>
using namespace std;
void gcd(int a,int b,int &d,int &x,int &y)
{
if(!b)
{
d=a,x=1,y=0;
}
else
{
gcd(b,a%b,d,y,x),y-=x*(a/b);
}
}
int main()
{
int p,e,d,i,a1,a2,a3,M1,M2,M3,t=0;
while(cin>>p>>e>>i>>d&&p+e+i+d>=0)
{
int x=0,y,q;
a1=p-d,a2=e-d,a3=i-d;
M1=924,M2=759,M3=644;
gcd(23,M1,q,q,y),x=(x+y*M1*a1)%21252;
gcd(28,M2,q,q,y),x=(x+y*M2*a2)%21252;
gcd(33,M3,q,q,y),x=(x+y*M3*a3)%21252;
x=(x%21252+21252)%21252,x=x?x:21252;
printf("Case %d: the next triple peak occurs in %d days.\n",++t,x);
}
return 0;
}
POJ1006 - Biorhythms(中国剩余定理)的更多相关文章
- POJ1006——Biorhythms(中国剩余定理)
Biorhythms Description人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色. ...
- Biorhythms(中国剩余定理)
http://shuxueshi.jie.blog.163.com/blog/static/13611628820104179856631/ 这篇博客写的很棒! #include<stdio.h ...
- POJ 1006 - Biorhythms (中国剩余定理)
B - Biorhythms Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1006 Biorhythms --中国剩余定理(互质的)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103539 Accepted: 32012 Des ...
- POJ 1006 Biorhythms(中国剩余定理)
题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...
- PKU POJ 1006 Biorhythms (中国剩余定理)
中国剩余定理 x = ai (mod mi) ai和mi是一组数,mi两两互质,求x 令Mi = m1*m2*~mk 其中,mi不包含在内. 因为mi两两互质,所以存在x和y, st M ...
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i ,求n . (题在文末) 知识点:中国剩余定理 ...
- poj1006 中国剩余定理&&中国剩余定理解析
poj 1006 题的思路不是很难的,可以转化数学式: 现设 num 是下一个相同日子距离开始的天数 p,e,i,d 如题中所设! 那么就可以得到三个式子:( num + d ) % 23 == p: ...
- 【中国剩余定理】 poj 1006
生理周期 简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...
- Biorhythms(poj1006+中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 117973 Accepted: 37026 Des ...
随机推荐
- CoreBluetooth - TouchID应用
支持系统和机型: iOS系统的指纹识别功能最低支持的机型为iPhone 5s,最低支持系统为iOS 8, 虽然安装iOS 7系统的5s机型可以使用系统提供的指纹解锁功能,但由于API并未开放,所以理论 ...
- MongoDB 配置文件启动
MongoDB 服务启动有两种方式:一种是直接命令启动,一种是通过配置文件启动 1.命令启动: mongod -dbpath C:\data\db -logpath C:\data\log\mongo ...
- 纯JavaScript实现一些小功能
题目链接:http://wenku.baidu.com/link?url=7Gbarr5q9X6h1QFRVAsHmfPp1xXagG209mvrJqBogseb4WLeRqbVKwxQieoh8SL ...
- [CC150] Get all permutations of a string
Problem: Compute all permutations of a string of unique characters. 此题用循环的方式不好做,下面是一种递归的思路: 把给的字符串看成 ...
- HttpOnly
Contents 1 Overview 1.1 Who developed HttpOnly? When? 1.2 What is HttpOnly? 1.3 Mitigating the Most ...
- Oracle SQL tuning 步骤
Oracle SQL tuning 步骤 SQL是的全称是Structured Query Language(结构化查询语言).SQL是一个在80年代中期被使用的工业标准数据库查询语言.不要把SQL语 ...
- SPRING IN ACTION 第4版笔记-第六章Rendering web views-001- Spring支持的View Resolver、InternalResourceViewResolver、JstlView
一.Spring支持的View Resolver 二.InternalResourceViewResolver Spring supports JSP views in two ways: Inte ...
- [Quick-x]制作新手引导高亮区域方法之二:裁剪模式
demo下载:https://github.com/chenquanjun/Quick-x-HighlightArea 2.裁剪模式 (1)创建裁剪对象 , , ) --非高亮区域颜色 local b ...
- Rails 撤销操作
即使再小心,在开发 Rails 应用程序过程中仍然可能犯错.幸运的是,Rails 提供了一些工具能够帮助你进行复原. 举例来说,一个常见的情况是,你想更改控制器的名字,这时你就要撤销生成的代码.生成控 ...
- RESTFul API 一些文章
http://www.ibm.com/developerworks/cn/web/1103_chenyan_restapi/index.html