hdu 1370 中国余数(剩余定理)
来源:互联网 发布:python pip安装windows 编辑:程序博客网 时间:2024/04/28 05:05
题意:
有3个循环周期,周期天数分别为23、28、33。对于某一年,已知某年这3个周期的某一峰值分别是当年的第p、e、i天,
问从第d天开始到最近一个满足3个周期都达到峰值的日期还有多少天。
初学者不会用模板 希望大牛可以指点我就是照着算法导论的推理一步一步写的
n=n1*n2*n3*......*nk
其中mi=n / ni
其中ci=mi (mi(逆元)mod ni)
a≡(a1*c1+a2*c2+.....+ak*ck)(mod n)
#include <iostream>using namespace std;int exgcd(int a,int b,int &x,int &y){ if(a==0) { x=0; y=1; return b; } int g = exgcd(b%a,a,x,y); int tem = y; y=x; x=tem-(b/a)*y; return g;}int inv(int a,int n)//求逆元{ int x,y; exgcd(a,n,x,y); return (x%n+n)%n;}int main(){ int N,P,E,I,D,ans; const int m1=23,m2=28,m3=33,M1=28*33,M2=23*33,M3=23*28,m=23*28*33; const int M11 = inv(M1,m1),M22 = inv(M2,m2),M33 = inv(M3,m3);//求mi的逆元 scanf("%d",&N); while(scanf("%d%d%d%d",&P,&E,&I,&D)!=EOF) { if(P==-1&&E==-1&&I==-1&&D==-1)break; //a[i]*(mi*mi(逆)mod ni)因为在求逆元的时候已经mod ni了 //(mi*mi(逆)mod ni)是ci ans = (P*M1*M11 + E*M2*M22 + I*M3*M33)%m; ans -= D; if(ans<=0) ans+=m; printf("Case %d: the next triple peak occurs in %d days.\n",N++,ans); //cout<<"Case "<<N++<<": the next triple peak occurs in "<<i<<" days.\n"; } return 0;}
- hdu 1370 中国余数(剩余定理)
- hdu-1370(中国剩余定理余数互质)&&hdu-1573(中国剩余定理余数不互质)
- [CODEVS3990]中国余数定理 2(中国剩余定理)
- 中国剩余定理(余数定理)Chinese remainder
- hdu 1370(中国剩余定理)
- HDU 1370 Biorhythms (中国剩余定理)
- hdu 1370 Biorhythms(中国剩余定理)
- HDU 1370(中国剩余定理)
- hdu 1370 中国剩余定理
- HDU 中国剩余定理
- code vs 3990 中国余数定理 2 (中国剩余定理)
- HDU 1370 Biorhythms(中国剩余定理 + 拓展欧几里得)
- HDU 1370 Biorhythms (中国剩余定理, 简单套用)
- HDU 1370 打表 || 中国剩余定理
- HDU 1370 Biorhythms 中国剩余定理
- hdu 1370 中国剩余定理+exgcd
- hdu 3579(中国剩余定理)
- hdu 1573(中国剩余定理)
- XAMPP Apache Service is already running on port 443
- 模版与泛型编程--<c++ primer>16章
- 金额中文大写转换工具类
- 几种比较好用的.htaccess配置
- js中this关键字的使用
- hdu 1370 中国余数(剩余定理)
- 有N个正实数(注意是实数,大小升序排列) x1 , x2 ... xN,另有一个实数M。 需要选出若干个x,使这几个x的和与 M 最接近。
- java IO详解(二)
- 排序算法之归并排序(分治法排序)
- BAPI_SALESORDER_CHANGE a sample of bapi which reject sales orders
- IIR与FIR基础知识
- VxWorks中WindML3.0的配置
- Poco 单元测试工具使用 for windows
- Ubuntu_11.40_server修改mysql的root用户密码