hdu1370-Biorhythms
来源:互联网 发布:小米5x手机壳淘宝卡通 编辑:程序博客网 时间:2024/05/29 14:42
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 ;int Case ;cin >> Case ;while( Case-- ){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;}if( Case != 0 )cout << endl ;}return 0 ;}
#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
- HDU1370-Biorhythms
- poj 1006 hdu1370 Biorhythms
- POJ1006 HDU1370 UVA756 Biorhythms
- HDU1370 Biorhythms【中国剩余定理】
- poj1006 / hdu1370 Biorhythms (中国剩余定理)
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Biorhythms
- Ext4+Servlet+HTML5实现实时获取文件上传进度、本地预览、文件拖拽上传的相册实例
- 风格化的 Toggle Buttons
- C++ 内存管理之五(数组 vs 指针)
- Android 读取assets目录下的文件
- 下拉列表默认选中--- jQuery
- hdu1370-Biorhythms
- 在内存对图片进行操作的时候注意小数的问题
- android margin vs padding
- java中的多态
- ulimit
- VIM复制粘贴系统剪贴板
- Jena进阶(一):简介+创建本体实例
- strcpy函数和strncpy函数的区别
- 关于JS截取字符串以及截取数组项的几种常见方法解析