HDU
来源:互联网 发布:mac idea groovy sdk 编辑:程序博客网 时间:2024/05/20 22:00
题目描述:
点击打开链接
题意:有三个周期,分别是23,28,33天,现给出三个周期的峰值分别是第,p,e,i天,现在是第d天,问距离最近的三个周期同时达到峰值的日期还有多少天。
假设日期为x,要使三个周期同时达到峰值,那么x%23=p%23,x%28=e%28,x%33=i%33,求出x之后(x-d)就是结果,那么这个方程组显然就是用中国剩余定理去解决。关于中国剩余定理:点击打开链接,具体实现直接看代码吧。
AC代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<string>#include<stack>#include<queue>#include<algorithm>using namespace std;const int MOD=21252;int p,e,i,d;int extgcd(int a,int b,int &x,int &y)//扩展欧几里德。{ int d=a; if (b!=0) { d=extgcd(b,a%b,y,x); y-=(a/b)*x; } else { x=1; y=0; } return d;}int china(int m0[],int b[]){ int x,y,n,m=1,a=0; for (int j=0;j<3;j++) m=m*m0[j]; for (int j=0;j<3;j++) { n=m/m0[j]; extgcd(n,m0[j],x,y); a=a+n*b[j]*x; } return a%m;}int main(){ char c; cin>>c; int cas=1; while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF) { if (p==-1&&e==-1&&i==-1&&d==-1) break; int m[3]={23,28,33}; int b[3]; b[0]=p,b[1]=e,b[2]=i; int sum=china(m,b)-d; if (sum<=0) sum+=MOD; printf("Case %d: the next triple peak occurs in %d days.\n",cas,sum); cas++; } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 【游戏跨场景寻路】基于as3语言的游戏地图跨场景寻路功能的实现
- linux 标准流管道 popen 源码理解
- Spring Ioc创建源码分析
- HDU 4027 Can you answer these queries?——其实是点更新的区间更新线段树
- C
- HDU
- 大端小端测试代码
- D
- hdu_2137_字符串旋转
- dpkg 被中断问题解决方法
- Python3之定制自己的数据类型
- opencv直方图该怎么画
- 关于URL截取?后面的字符串并转换成对象的问题简述
- 递归与动态规划---数组中的最长连续序列