POJ1006 Biorhythms (CRT)

来源:互联网 发布:影视包装培训软件 编辑:程序博客网 时间:2024/05/16 05:48

题目点我点我点我


题意:点右上角可选中文不解释。


解题思路:赤裸裸的CRT,模版一套就可。


/* ***********************************************┆  ┏┓   ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃       ┃ ┆┆┃   ━   ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃       ┃ ┆┆┃   ┻   ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆  ┃ 勒 ┃  ┆      ┆  ┃ 戈 ┗━━━┓ ┆┆  ┃ 壁     ┣┓┆┆  ┃ 的草泥马  ┏┛┆┆  ┗┓┓┏━┳┓┏┛ ┆┆   ┃┫┫ ┃┫┫ ┆┆   ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)#define pb push_back#define mp make_pairconst int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define LL long long#define ULL unsigned long long#define MS0(X) memset((X), 0, sizeof((X)))#define SelfType intSelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}#define Sd(X) int (X); scanf("%d", &X)#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}//#pragma comment(linker, "/STACK:102400000,102400000")void extend_gcd(int a,int b,int &x,int &y){    if(b==0)    {        x = 1,y = 0;        return;    }    extend_gcd(b,a%b,x,y);    int temp = x;    x = y;    y = temp - (a / b) * y;}int CRT(int a[],int m[],int n){    int M = 1,ans = 0;    for(int i=1;i<=n;i++)        M *= m[i];    for(int i=1;i<=n;i++)    {        int x,y;        int Mi = M / m[i];        extend_gcd(Mi,m[i],x,y);        ans = (ans + Mi*x*a[i]) % M;    }    if(ans<0)ans += M;    return ans;}int aa[4],mm[4];int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);ios::sync_with_stdio(0);cin.tie(0);int p,e,i,d,cas = 1;while(~scanf("%d%d%d%d",&p,&e,&i,&d))    {        if(p == -1 && e == -1 && i == -1 && d == -1) break;        aa[1] = p, aa[2] = e, aa[3] = i;        mm[1] = 23, mm[2] = 28, mm[3] = 33;        int ans = CRT(aa,mm,3);        if(ans<=d)ans += 21252;        printf("Case %d: the next triple peak occurs in %d days.\n",cas++,ans-d);    }return 0;}


0 0
原创粉丝点击