poj 1006 Biorhythms
来源:互联网 发布:beta软件计划 编辑:程序博客网 时间:2024/06/05 07:33
今天学完B树之后想顺手做一道poj,依次下来今天轮到1006,但是读完题目发现这道题目似乎是个数论题目,没有思路。于是上网搜,发现这道题目是个中国余数定理的题目,没办法,研究了一晚上的中国余数定理,感觉算法导论中这部分的内容好像将不是很清楚,于是参考了http://blog.csdn.net/jiaobuchong/article/details/40585575这篇文章,终于把中国余数定理弄明白了,理论上逆元应该用扩展欧几里得算法算一下,但今天实在没时间看他了,于是手工算了一下逆元,就是代码中的a1,a2,a3,一开始是WA,后来下了测试数据发现,我的结果里面有两组数据出现了负值,果断修改了代码,顺利通过。
特别注意逆元的求解方法。
Source Code
Problem: 1006 User: zhyh2010Memory: 240K Time: 79MSLanguage: C++ Result: Accepted#include <iostream>using namespace std;const int period1 = 23;const int period2 = 28;const int period3 = 33;int main(int argc, char ** argv){unsigned int m1 = period3*period2;unsigned int m2 = period3*period1;unsigned int m3 = period1*period2;unsigned int total = period1*period2*period3;unsigned int a1 = 6;unsigned int a2 = 19;unsigned int a3 = 2;int a, b, c, d;int count = 0;while (cin >> a >> b >> c >> d){if (a == -1 && b == -1 && c == -1 && d == -1){break;}int res;res = (m1*a1*a + m2*a2*b + m3*a3*c) % total;/*if (res == 0){res += total;}res -= d;*/res -= d;res <= 0 ? res += total : res;// outputcout << "Case " << ++count << ": the next triple peak occurs in " << res << " days." << endl;}return 0;}
0 0
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- 【POJ】1006 Biorhythms
- POJ-1006:Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 Biorhythms
- POJ 1006 Biorhythms
- Poj 1006 Biorhythms
- POJ 1006 Biorhythms
- poj 1006 hdu1370 Biorhythms
- 【POJ】1006 Biorhythms
- poj 1006 Biorhythms
- scandir 函数
- 5 Open Source Business Intelligence Tools[翻译]
- POJ2823——Sliding Window 单调队列入门
- vim多窗口编辑
- UVA10183 - How Many Fibs?(java大数+二分)
- poj 1006 Biorhythms
- C#MD5加密16进制写法
- 如何更改MFC程序图标
- 几种平衡树的总结
- brk(), sbrk() 用法详解 (转)
- wp开发 progress bar的制作
- [操作系统]iOS开发之使用CocoaPods更新第三方出现“target overrides the `OTHER_LDFLAGS`……”问题解决方案
- 酷宝童车便携式代步系列近二百款
- BP 神经网络的 MATLAB 实现步骤