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
  • 相关阅读:
    SAP Hybris使用recipe进行安装时,是如何执行ant命令的?
    实时电商数仓(三)之数据采集(二)搭建日志采集系统的集群(二)建立父工程
    实时电商数仓(一)之系统架构
    gdb 条件断点 + 多线程 +attach
    dpdk tx_pkt_burst rte_pktmbuf_free mbuf释放
    dpdk 网卡初始化 —— 收包
    dpdk 版本变动修改
    rte_mempool_get_priv
    mempool + ring test
    dpdk mempool debug
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9322606.html
Copyright © 2011-2022 走看看