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 ...
随机推荐
- IT第四天 - 运算符、随机数、Math类
IT第四天 上午 运算符 1.%运算符的应用 2.运算符优先级:小括号 ! 算数运算符 关系运算符 && || 赋值运算符 3.三元运算符:?表示条件为true的结果,:表示条件为 ...
- 奔小康赚大钱(km)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- org.tigris.subversion.javahl.ClientException: Attempted to lock an already-locked dir svn: Working c
Eclipse插入svn提交出现:org.tigris.subversion.javahl.ClientException: Attempted to lock an already-locked d ...
- HDU2276 - Kiki & Little Kiki 2(矩阵高速幂)
pid=2276">题目链接 题意:有n盏灯.编号从1到n.他们绕成一圈,也就是说.1号灯的左边是n号灯.假设在第t秒的时候,某盏灯左边的灯是亮着的,那么就在第t+1秒的时候改变这盏灯 ...
- 友盟iOS微信登陆没有回调的原因
1.在友盟文档中这样说: 链接 7.4 微信登录 添加配置文件参考文档:添加微信及朋友圈,添加相关库文件,配置URL schemes及添加系统回调 注意微信登录必须先在微信开放平台申请微信登录权限 在 ...
- iOS中NSString转换成HEX(十六进制)-NSData转换成int
http://www.2cto.com/kf/201402/281501.html 1 2 3 4 5 6 NSString *str = @"0xff055008"; //先以1 ...
- Altera FPGA中的pin进一步说明
最近END china上的大神阿昏豆发表了博文 <FPGA研发之道(25)-管脚>,刚好今天拿到了新书<深入理解Altera FPGA应用设计>第一章开篇就讲pin.这里就两者 ...
- Week5(10月10日):国庆之后,让我们整装期待元旦吧
Part I:提问 =========================== 1.要将“Hello, Admin",从控制器传递到视图,该如何操作? (1)使用ViewData (2)使用V ...
- STRUTS2获得session和request
在struts1中,获得到系统的request或者session对象非常方便,都是按照形参传递的,但是在struts2中,request和session都被隐藏了struts提供两种方式访问sessi ...
- 测试css2.1选择器IE6/7/8支持情况,属性选择器/子元素/相邻
环境 xp ie 8 , ietester <!doctype html> <html> <head> <meta charset="utf-8&q ...