生理周期  简单模拟

对于超出23 * 28 * 33(21252)时进行求余运算即可。

#include<stdio.h>
int main()
{
//freopen("in.txt","r",stdin);
int a,b,c,d,s,m=;
while(scanf("%d %d %d %d",&a,&b,&c,&d),(a!=-||b!=-||c!=-||d!=-))
{
s=a;
if(b>s)
s=b;
if(c>s)
s=c;
do
{
s++;
}while (((s+d-a)%!=)|| ((s+d-b))%!= ||((s+d-c)%!=) );
if(s>)
s=s%;
printf("Case %d: the next triple peak occurs in %d days.\n",m,s);
m++;
}
return ;
}

中国剩余定理
若某数x分别被d1、、…、dn除得的余数为r1、r2、…、rn,则可表示为下式:
x=R1r1+R2r2+…+Rnrn+RD
其中R1是d2、d3、…、dn的公倍数,而且被d1除,余数为1;
R1 、R2…、

Rn是d1、d2、…、dn-1的公倍数,而且被dn除,余数为1;
D是d1、d2、…、的最小公倍数;
R是任意整数,可根据实际需要决定;
且d1、、…、必须互质,以保证每个Ri(i=1,2,…,n)都能求得.
实际上POJ1006就是中国剩余定理的典型应用
根据上面的条件求出常数R1 = 5544,R2 = 14421,R3 = 1288,D = 21252
每次给的数据中的前三个值即相当于上面的余数。
则显然:
res = R1 * Physical + R2 * Emotion + R3 * Intelligence + RD - givenDate
并且0 =< res <= D

#include <stdio.h>
int main()
{
int R1 = , R2 = , R3 = , R = ;
int ph, em, in, day;
int res,i;
for(i=; ; i++){
scanf("%d%d%d%d", &ph, &em, &in, &day);
if(ph==-)break;
res = (R1 * ph + R2 * em + R3 * in - day) % R; res = (res + R - ) % R + ; //此步处理了负数和零的两种边界情况
printf("Case %d: the next triple peak occurs in %d days.\n", i, res);
}
return ;
}

提交结果:

模拟          782MS

中国剩余定理  32MS

太高端了!!!!!!

【中国剩余定理】 poj 1006的更多相关文章

  1. 中国剩余定理 POJ 1006 Biorhythms

    题目传送门 题意:POJ有中文题面 分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板 代码: /********* ...

  2. POJ 1006 - Biorhythms (中国剩余定理)

    B - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Subm ...

  3. POJ 1006 Biorhythms(中国剩余定理)

    题目地址:POJ 1006 学习了下中国剩余定理.參考的该博客.博客戳这里. 中国剩余定理的求解方法: 假如说x%c1=m1,x%c2=m2,x%c3=m3.那么能够设三个数R1,R2,R3.R1为c ...

  4. 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms

    题目链接: http://poj.org/problem?id=1006 http://acm.hdu.edu.cn/showproblem.php?pid=1370 题目大意: (X+d)%23=a ...

  5. POJ 1006 生理周期(中国剩余定理)

    POJ 1006 生理周期 分析:中国剩余定理(注意结果要大于d即可) 代码: #include<iostream> #include<cstdio> using namesp ...

  6. poj 1006 Biorhythms (中国剩余定理模板)

    http://poj.org/problem?id=1006 题目大意: 人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这 ...

  7. POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理)

    POJ.1006 Biorhythms (拓展欧几里得+中国剩余定理) 题意分析 不妨设日期为x,根据题意可以列出日期上的方程: 化简可得: 根据中国剩余定理求解即可. 代码总览 #include & ...

  8. POJ 1006 Biorhythms (中国剩余定理)

    在POJ上有译文(原文右上角),选择语言:简体中文 求解同余方程组:x=ai(mod mi) i=1~r, m1,m2,...,mr互质利用中国剩余定理令M=m1*m2*...*mr,Mi=M/mi因 ...

  9. poj 1006中国剩余定理模板

    中国剩余定理(CRT)的表述如下 设正整数两两互素,则同余方程组 有整数解.并且在模下的解是唯一的,解为 其中,而为模的逆元. 模板: int crt(int a[],int m[],int n) { ...

  10. poj 1006:Biorhythms(水题,经典题,中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Des ...

随机推荐

  1. POJ 2425 A Chess Game#树形SG

    http://poj.org/problem?id=2425 #include<iostream> #include<cstdio> #include<cstring&g ...

  2. OpenLayer

    <html> <head> <meta charset="utf-8"> <title>GIS开发样例-V1.0</title ...

  3. CDOJ 1270 Playfair(模拟)

    题目链接 Playfair is a kind of substitution cipher.And the encryption role is simple.In general,there ar ...

  4. 查看linux系统版本是32位还是64位

    如何查看ubuntu版本是64位还是32位的: 1.# uname -a 如果有x86_64就是64位的,没有就是32位的 2.# uname -mx86_64 3.# archx86_6 如何查看u ...

  5. 安装mcrouter

    下载准备: mcrouter 下载地址 : https://github.com/facebook/mcrouter gflags 下载地址:http://download.csdn.net/deta ...

  6. 1.编写TextRw.java的Java应用程序,程序完成的功能是:首先向TextRw.txt中写入自己的学号和姓名,读取TextRw.txt中信息并将其显示在屏幕上。

    package zuoye; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; ...

  7. IE8"开发人员工具"使用详解下(浏览器模式、文本模式、JavaScript调试、探查器)

    来源: http://www.cnblogs.com/JustinYoung/archive/2009/04/03/kaifarenyuangongju2.html 在上一篇文章IE8“开发人员工具” ...

  8. [Python] spides

    摘要:本文将介绍用Python进行的爬虫的各种练习以及涉及到的各种知识,包括Http协议,cookie等等 工具 Fiddler Python默认不用代理,所以fiddler不能截取它的包.如果想用用 ...

  9. 基于Centos6.6的R720服务器四网口端口聚合的实践

    服务器多网口端口聚合,其目的主要在于网卡容灾和提升带宽.linux端口绑定,提供7种模式,如下: 关于mode共有0-6等7种模式,详细请参考官方手册!mode的值表示工作模式,他共有0,1,2,3, ...

  10. Struts2--课程笔记3

    获取ServletAPI: 第一种方式: //在request域中放入属性req,暂且认为getContext()获取的是request域空间,但实际不是        ActionContext.g ...