Biorhythms (POJ1006)
2016-05-10 14:38
323 查看
题目概述:
已知 三个变量 p e i ;为三个周期循环的起始时间,其周期分别为23 28 33。
求三个循环同时结束时,距d的时间。
即为求三个同余方程 x=p mod 23 x=e mod 28 x=p mod 33;
利用中国剩余定理可得 解 x=(1288 * c + 14421 * b + 5544 * a ) % 21252。
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d,i=1;
while (cin >> a >> b >> c >> d, d != -1)
{
a %= 23;
b %= 28;
c %= 33;
int out = (1288 * c + 14421 * b + 5544 * a - d + 21252) % 21252;
if (out==0)
{
cout << "Case "<<i<<": the next triple peak occurs in " << 21252 << " days." << endl;
}
else
{
cout << "Case " << i << ": the next triple peak occurs in " << out << " days." << endl;
}
i++;
}
}
已知 三个变量 p e i ;为三个周期循环的起始时间,其周期分别为23 28 33。
求三个循环同时结束时,距d的时间。
即为求三个同余方程 x=p mod 23 x=e mod 28 x=p mod 33;
利用中国剩余定理可得 解 x=(1288 * c + 14421 * b + 5544 * a ) % 21252。
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d,i=1;
while (cin >> a >> b >> c >> d, d != -1)
{
a %= 23;
b %= 28;
c %= 33;
int out = (1288 * c + 14421 * b + 5544 * a - d + 21252) % 21252;
if (out==0)
{
cout << "Case "<<i<<": the next triple peak occurs in " << 21252 << " days." << endl;
}
else
{
cout << "Case " << i << ": the next triple peak occurs in " << out << " days." << endl;
}
i++;
}
}
相关文章推荐
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- POJ 2159 Ancient Cipher
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- POJ1050 最大子矩阵和
- 用单调栈解决最大连续矩形面积问题
- 2632 Crashing Robots的解决方法
- POJ——3253 Fence Repair