http://acm.hdu.edu.cn/showproblem.php?pid=1370

中国剩余定理

已知(n+d)%23=a;   (n+d)%28=b;   (n+c)%33=i 
       使33×28×a被23除余1,用33×28×6=5544; 
       使23×33×b被28除余1,用23×33×19=14421; 
       使23×28×c被33除余1,用23×28×2=1288。 
      因此有(5544×p+14421×e+1288×i)% lcm(23,28,33) =n+d

又23、28、33互质,即lcm(23,28,33)= 21252;
      所以有n=(5544×p+14421×e+1288×i-d)%21252

本题所求的是最小整数解,避免n为负,因此最后结果为n= [n+21252]% 21252
那么最终求解n的表达式就是:

n=(5544*p+14421*e+1288*i-d+21252)%21252;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset> using namespace std; int main()
{
int a , b , c , d ;
int temp = 0 ;
while( cin >> a >> b >> c >> d )
{
if( a == - 1 && b == -1 && c == -1 && d == -1 )
break;
int n = ( 5544 * a + 14421 * b + 1288 * c ) % 21252 ;
int ans = n > d ? n - d : 21252 + n - d ;
cout << "Case " << ++temp << ": the next triple peak occurs in " << ans << " days." << endl;
}
return 0 ;
}

同样,这道题的解法就是:

已知(n+d)%23=p;   (n+d)%28=e;   (n+d)%33=i 
       使33×28×a被23除余1,用33×28×8=5544; 
       使23×33×b被28除余1,用23×33×19=14421; 
       使23×28×c被33除余1,用23×28×2=1288。 
      因此有(5544×p+14421×e+1288×i)% lcm(23,28,33) =n+d

又23、28、33互质,即lcm(23,28,33)= 21252;
      所以有n=(5544×p+14421×e+1288×i-d)%21252

本题所求的是最小整数解,避免n为负,因此最后结果为n= [n+21252]% 21252
那么最终求解n的表达式就是:

n=(5544*p+14421*e+1288*i-d+21252)%21252;

当问题被转化为一条数学式子时,你会发现它无比简单。。。。直接输出结果了。


hdu1370-Biorhythms的更多相关文章

  1. 中国剩余定理+扩展中国剩余定理 讲解+例题(HDU1370 Biorhythms + POJ2891 Strange Way to Express Integers)

    0.引子 每一个讲中国剩余定理的人,都会从孙子的一道例题讲起 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何? 1.中国剩余定理 引子里的例题实际上是求一个最小的x满足 关键是,其中 ...

  2. poj1006 / hdu1370 Biorhythms (中国剩余定理)

    Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p;   (n+d)%28=e;   (n+d)%33=i ,求n .        (题在文末) 知识点:中国剩余定理 ...

  3. (EX)中国剩余定理

    中国剩余定理 问题引入: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何?<孙子算经> 就是计算一个数\(x\)满足\(\begin{cases} x≡2(MOD\ 3) ...

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

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

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

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

  6. [POJ] #1006# Biorhythms : 最小公倍数/同余问题

    一. 题目 Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127263   Accepted: 403 ...

  7. Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期

    1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...

  8. 算法练习之:Biorhythms

    Biorhythms Time Limit: 1000MS Memory Limit: 10000KB  Problem Description Some people believe that th ...

  9. Biorhythms(中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 127339   Accepted: 40342 Des ...

  10. POJ - 1006 Biorhythms 周期相遇 两个思路程序

    Description Some people believe that there are three cycles in a person's life that start the day he ...

随机推荐

  1. Robotium之Android控件定位实践和建议(Appium/UIAutomator姊妹篇)

    本人之前以前撰文描写叙述Appium和UIAutomator框架是怎样定位Android界面上的控件的. UIAutomator定位Android控件的方法实践和建议 Appium基于安卓的各种Fin ...

  2. windows 不能在 本地计算机 启动 Apache

    可能是Apache 的监听端口与其他软件有冲突,这是新手常犯的一个错误,Windows安装了IIS服务器的同时,又安装Apache服务器,二个服务器软件都监听TCP/IP协议的80端口,于是就有其中的 ...

  3. iOS 之 UINavigationController 记录

    有一阵子没有写随笔,感觉有点儿手生.一个多月以后终于又一次坐下来静下心写随笔,记录自己的学习笔记,也希望能够帮到大家. 废话少说回到正题,UINavigationController是IOS编程中比较 ...

  4. ubuntu安装greenplum依赖包

    ubuntu安装greenplum的过程中有两个比较难找的包,特地写出来给大家分享一下: 错误提示1:configure: error: header file <ldap.h> is r ...

  5. windows服务怎么向应用程序发消息(部署在同一台机,非SCOKET)

    命名管道:NamedPipeClientStream & NamedPipeClientStream 参考实例:http://msdn.microsoft.com/zh-cn/library/ ...

  6. VirtualBox虚拟机安装RedHat7.3编译Linux0.01内核

    引子 由于需要编译linux0.01内核,而目前的linux版本太高需要降低gcc版本等等,需要做不少调整非常不方便. 所以,直接安装RedHat7.3,这样就好编译linux0.01的内核了. 但是 ...

  7. 几个BCB例子

    http://blog.163.com/tab_98/blog/static/11924097201511274543737/

  8. 让Solr返回JSON数据

    http://localhost:1985/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on& ...

  9. zk create() 方法

    create() $path = $zkh->create($req_path, $data); $path = $zkh->create($req_path, $data, 'flags ...

  10. stm32之watchdog

    在嵌入式系统中,由于MCU的工作常常受到来自外界电磁场的干扰,造成程序的跑飞,而陷入死循环,程序的正常运行被打断,由单片机控制的系统无法继续工作,会造成整个系统陷入停滞状态,发送不可预料的后果,所以出 ...