zoukankan      html  css  js  c++  java
  • HDU 1370: Biorhythms

    1

    0 0 0 0
    0 0 0 100
    5 20 34 325
    4 5 6 7
    283 102 23 320
    203 301 203 40
    -1 -1 -1 -1

    Case 1: the next triple peak occurs in 21252 days.
    Case 2: the next triple peak occurs in 21152 days.
    Case 3: the next triple peak occurs in 19575 days.
    Case 4: the next triple peak occurs in 16994 days.
    Case 5: the next triple peak occurs in 8910 days.
    Case 6: the next triple peak occurs in 10789 days.

    分析

    可以维护一个bool数组暴力模拟,也可以中国剩余定理。

    (n+d)%23=a,(n+d)%28=b,(n+d)%33=c;

    所以,n=(33*28*6*p+23*33*19*e+1288*i)%lcm(23,28,33)=n+d

    即ans=(5544p+14421e+1288i-d)%21252

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define LL long long
    #define CLS(arr) memset(arr,0,sizeof(arr))
    using namespace std;
    bool days[21255];
    int p,e,i,d;
    void solve(){
        int ans,cnt=0;
        while(cin>>p>>e>>i>>d,p!=-1&&e!=-1&&i!=-1&&d!=-1){
            CLS(days);
            for(int k=p;k<=21252;k+=23)days[k]=true;
            range(k,0,21252)days[k]=(k-e)%28?false:days[k]?true:false;
            range(k,0,21252)days[k]=(k-i)%33?false:days[k]?true:false;
            range(k,d+1,21252)if(days[k]){ans=k;break;}
            cout<<"Case "<<++cnt<<": the next triple peak occurs in "<<ans-d<<" days."<<endl;
        }
    }
    int main(int argc, char *argv[]){
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    [Android]Parcelable encountered IOException writing serializable object (name = xxx)
    开机黑屏 仅仅显示鼠标 电脑黑屏 仅仅有鼠标 移动 [已成功解决]
    poj3070--Fibonacci(矩阵的高速幂)
    Java泛型解析(03):虚拟机运行泛型代码
    PHP中的替代语法
    在ubuntu上部署hadoop时出现的问题
    js闭包(函数内部嵌套一个匿名函数:这个匿名函数可将所在函数的局部变量常驻内存)
    js匿名函数(变量加括号就是函数)
    javascript进阶课程--第三章--匿名函数和闭包
    js实现科学计算机
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9322606.html
Copyright © 2011-2022 走看看