POJ 1006 Biorhythms (中国剩余定理)
来源:互联网 发布:caffe经典模型实战pdf 编辑:程序博客网 时间:2024/05/01 19:10
题目大意:找比某一个数大的,对23,28,33三个数模运算得到结果固定的数。
解题方法:中国剩余定理的简单应用,因为数据太小也可以考虑直接暴力。关于中国剩余定理,我认为刘汝佳的训练指南上面就讲的非常好了,以后如果有时间我再把这部分补充上来。
AC代码:
#include <iostream>#include <cstdio>using namespace std;typedef long long ll;ll exgcd(ll a, ll b, ll &x, ll &y){ if(b==0) { x = 1; y = 0; return a; } ll d = exgcd(b,a%b,x,y); ll temp = x; x = y; y = temp - a/b*y; return d;}// n个方程 x = a[i] (mod m[i]) ( 0 =< i < n)ll china(int n, int* a, int* m){ ll M = 1, d, y, x = 0; for(int i = 0; i<n; i++) { M *= m[i]; } for(int i = 0; i<n; i++) { ll w = M / m[i]; exgcd(m[i], w, d, y); x = (x + y*w*a[i]) % M; } return (x+M)%M;}int main(){ int m[5] = {23,28,33}; int a[5]; int date = 0, k = 1; while(1) { for(int i = 0; i<3; i++) { cin>>a[i]; } cin>>date; if(date==-1) break; int ans = china(3,a,m); ans = (ans - date) % 21252; if(ans<=0) ans += 21252; printf("Case %d: the next triple peak occurs in %d days.\n", k++, ans); } //cout << "Hello world!" << 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 Biorhythms (中国剩余定理)
- poj 1006 Biorhythms (中国剩余定理)
- POJ 1006 Biorhythms (中国剩余定理)
- 自定义View常见问题
- react-native当点击TouchableOpacity时,要点击两下才会触发onPress解决办法
- Android:RxJava了解
- 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。
- 基于epoll的聊天室程序
- POJ 1006 Biorhythms (中国剩余定理)
- 七种滤波方法的matlab实现和测试
- java中list集合的深度拷贝
- choose属性的使用(radio,checked)
- NSUserActivity的基本使用
- 求两个数的最大公约数和最小公倍数
- 工作记录之Spring学习笔记(1)集合的注入
- git实战1
- 珠海空号检测的运行原理