HDU 1370 Biorhythms 中国剩余定理
2017-04-20 19:42
357 查看
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=1370题意:
人有体力,情感和智力三个生理周期,分别为23,28和33天。一个周期内有一天为峰值,对应的体力(情感或智力)达到巅峰。现在分别给出当前年内三个生理周期达到峰值的那一天,再给出一个d,问从第d天到下一个三个周期都达到峰值的日期还有多少天思路:
中国剩余定理模板题啊。有同余方程组ai≡x(modmi),其中i∈[1,k],所有的mi互质,所有的mi乘积为m,那么有x≡∑ki=1aici(modn),ci=tm∗tm−1(modmi),tm=m/mi#include <bits/stdc++.h> using namespace std; const int N = 110; int cas = 0; int extgcd(int a, int b, int &x, int &y) { int d = a; if(b) { d = extgcd(b, a%b, y, x); y -= (a/b) * x; } else x = 1, y = 0; return d; } int crt(int A[], int M[], int n) { int m = 1; for(int i = 1; i <= n; i++) m *= M[i]; int ans = 0, x, y; for(int i = 1; i <= n; i++) { int tm = m / M[i]; extgcd(tm, M[i], x, y); ans = (ans + A[i] * tm * x) % m; } if(ans < 0) ans += m; return ans; } int main() { int t, a , m = {0, 23, 28, 33}; int s; scanf("%d", &t); while(t--) { while(true) { for(int i = 1; i <= 3; i++) scanf("%d", &a[i]); scanf("%d", &s); if(a[1] == -1 && a[2] == -1 && a[3] == -1 && s == -1) break; int res = crt(a, m, 3); if(res <= s) res += 21252; printf("Case %d: the next triple peak occurs in %d days.\n", ++cas, res - s); } } return 0; }
相关文章推荐
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
- hdu_1370Biorhythms(互素的中国剩余定理)
- 【中国剩余定理】POJ 1006 & HDU 1370 Biorhythms
- hdu 1370 Biorhythms 中国剩余定理的应用 and 枚举方法
- HDU1370 Biorhythms【中国剩余定理】
- HDU 1370 Biorhythms(中国剩余定理 + 拓展欧几里得)
- hdu 1370 中国剩余定理
- 中国剩余定理 hdoj 1370 Biorhythms
- hdoj-1370-Biorhythms【中国剩余定理】
- hdu 1370 Biorthythms 中国剩余定理
- hdu 1370 || poj 1006 简单的中国剩余定理或者暴力
- hdu-1370(中国剩余定理余数互质)&&hdu-1573(中国剩余定理余数不互质)
- hdu 1370 中国剩余定理
- HDU 1788 中国剩余定理
- POJ 1006 Biorhythms 中国剩余定理
- hdu 1573 X问题 中国剩余定理
- HDU X问题 中国剩余定理--求满足条件的个数
- POJ 1006 Biorhythms --中国剩余定理(互质的)
- hdu 1573 X问题 非互素的中国剩余定理应用
- hdu 3579 Hello Kiki 中国剩余定理(不互质形式)模板题