zoukankan      html  css  js  c++  java
  • poj 1006 Biorhythms

    题目:Biorhythms

    思路: 扩展欧几里得 

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <cstdlib>
    #include <map>
    using namespace std;
    int w[4]={0,23,28,33},a[4];
    long long exgcd(long long a,long long b,long long &x,long long &y)
    {
        if(b==0)
        {
            x=1;
            y=0;
            return a;
        }
        else
        {
            long long ans=exgcd(b,a%b,x,y);
            long long t=x;
            x=y;
            y=t-a/b*y;
            return ans;
        }
    }
    int CRT(int r)
    {
        long long M=1;
        long long i,d,x0,y0,ans=0;
        for(i=1;i<=r;i++)
            M*=w[i];//好像很容易溢出的样子,CRT弱爆了
        for(i=1;i<=r;i++)
        {
            d=M/w[i];
            exgcd(d,w[i],x0,y0);
            ans=(ans+d*x0*a[i])%M;
        }
        while(ans<= 0)
           ans+=M;
        return ans;
    }
    int main()
    {
        int ca=0;
        int d;
        while(scanf("%d%d%d%d",&a[1],&a[2],&a[3],&d)!=EOF)
        {
            if(a[1]==-1&&a[2]==-1&&a[3]==-1&&d==-1)
                break;
            int M=1;
            for(int i=1;i<=3;i++)
                M*=w[i];
            int ans=CRT(3);
            ans-=d;
            while(ans<=0)
                ans+=M;
            printf("Case %d: the next triple peak occurs in %d days.
    ",++ca,ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    docker网络
    docker-registry搭建
    JDK1.8源码安装
    docker-compose应用
    docker-compose介绍
    docker commit
    CMD/ENTROYPOINT区别
    第一个dockerfile
    SpringBoot整合Mybatis对单表的增、删、改、查操作
    向上取整、向下取整
  • 原文地址:https://www.cnblogs.com/overflow/p/3193520.html
Copyright © 2011-2022 走看看