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. poj 1084 Brainman(归并排序)

    题目链接:http://poj.org/problem?id=1804 思路分析:序列的逆序数即为交换次数,所以求出该序列的逆序数即可. 根据分治法思想,序列分为两个大小相等的两部分,分别求子序列的逆 ...

  2. ThinkPHP - CURD增删改查 - 实例

    目录结构:

  3. java的数据类型,几个java小程序

    1:求圆的面积 还好看了c++,不然直接看这课件还真是看不懂……加油吧 要从键盘读入数据可以用Scanner类的nextlnt()或者nextDouble()方法,首先创建Scanner类的一个实例, ...

  4. [Swust OJ 137]--波浪数(hash+波浪数构造)

    题目链接:http://acm.swust.edu.cn/problem/137/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  5. django-debug-toolbar

    一:安装django-debug-toolbar. 二:在settings里的MIDDLEWARE_CLASSES加入'debug_toolbar.middleware.DebugToolbarMid ...

  6. Solr4.7缓存技术

    磁盘IO往往是计算机系统响应速度的一个突出瓶颈,搜索引擎查询很平凡,减少搜索过程中的磁盘IO对提升搜索响应速度无疑有莫大的帮助,在solr中,提供自带的缓存机制.我们只需要在solrconfig.xm ...

  7. Android自定义组合控件:UIScrollLayout(支持界面滑动及左右菜单滑动)

    一.前言: 我之前很早的时候,写过一篇<左右滑出菜单>的文章: http://blog.csdn.net/qingye_love/article/details/8776650 用的是对V ...

  8. 基于visual Studio2013解决C语言竞赛题之0517矩阵

     题目

  9. 深入解析MFC -- 句柄与对象的关系

    CWnd::FromHandlePermanent ——根据窗口句柄得到CWnd*指针 This function, unlike FromHandle, does not create tempor ...

  10. Debian为程序添加一个开始菜单,debian添加sublime开始菜单.

    下了一个 '绿色' 的程序,想要加到开始菜单里面. 怎么做呢? 我这里以sublime2做例 去http://www.sublimetext.com/2 下载了linux 64位, 解压放到了下面的文 ...