hdu1370-Biorhythms
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的更多相关文章
- 中国剩余定理+扩展中国剩余定理 讲解+例题(HDU1370 Biorhythms + POJ2891 Strange Way to Express Integers)
0.引子 每一个讲中国剩余定理的人,都会从孙子的一道例题讲起 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何? 1.中国剩余定理 引子里的例题实际上是求一个最小的x满足 关键是,其中 ...
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
Biorhythms 题意:读入p,e,i,d 4个整数,已知(n+d)%23=p; (n+d)%28=e; (n+d)%33=i ,求n . (题在文末) 知识点:中国剩余定理 ...
- (EX)中国剩余定理
中国剩余定理 问题引入: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何?<孙子算经> 就是计算一个数\(x\)满足\(\begin{cases} x≡2(MOD\ 3) ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- 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: 127263 Accepted: 403 ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- 算法练习之:Biorhythms
Biorhythms Time Limit: 1000MS Memory Limit: 10000KB Problem Description Some people believe that th ...
- Biorhythms(中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 127339 Accepted: 40342 Des ...
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
随机推荐
- 宣布正式发布 Biz Talk Services、Azure Active Directory 和 Traffic Manager, 同时发布 Azure Active Directory 高级版预览
除经济优势之外,云计算还在可转化为竞争优势的应用程序开发方面提供了更大的灵活性.我们很高兴看到每天创建的新 Windows Azure 订阅超过 1000 个,更令人兴奋的是,有一半客户使用价值更高的 ...
- uva 10599 - Robots(II) (dp | 记忆化搜索)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- ViewPager引导页效果实例源码
首先大家先找到本地的sdk,然后找到Google提供的API,具体查找方法如下:sdk——>docs——>index.html——>develop——>training——&g ...
- ViewPager+Fragment实现支持左右滑动的Tab
主要思想:顶部标题栏top.xml,中间ViewPager(4个Fragment),底部导航 top.xml和bottom.xml在我之前的两个随笔里有,此处不再赘述. activity_main.x ...
- BZOJ 1036: [ZJOI2008]树的统计Count( 树链剖分 )
树链剖分... 不知道为什么跑这么慢 = = 调了一节课啊跪.. ------------------------------------------------------------------- ...
- javascript 数组部分
<html> <body> <script type="text/javascript"> var arr = new Array(6) arr ...
- ContentProvider中的数据生成时机
目录结构: , 先给个结论: 仅仅是实例化mySqliteHelper()这个类的时候是不会创建数据库的,实际上数据库的真正创建是在helper.getWritableDatabase()的方法执行后 ...
- github过程中收集
github过程中收集 <HelloGithub月刊>第三期 <HelloGithub>第三期 兴趣是最好的老师,而<HelloGithub> 就是帮你找到兴趣 ...
- 简单实用的下拉菜单(CSS+jquery)
原文 简单实用的下拉菜单(CSS+jquery) 没什么可以说的,直接上例子 html+jquery代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...
- 基于visual Studio2013解决C语言竞赛题之0607strcpy
题目