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
  • 相关阅读:
    关于BlockingQueue
    关于java的线程
    mongodb的锁和高并发
    innodb的锁和高并发
    mysql的事务隔离级别及其使用场景
    mongodb分页
    ReentrantLock和Synchronized
    spring boot MVC
    svn 入门
    多线程的返回值等问题
  • 原文地址:https://www.cnblogs.com/overflow/p/3193520.html
Copyright © 2011-2022 走看看