zoukankan      html  css  js  c++  java
  • POJ1006 Biorhythms

    题目链接:点击打开链接

    Biorhythms

    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 144625   Accepted: 46587

    Description

    Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field (physical, emotional or mental). For example, if it is the mental curve, thought processes will be sharper and concentration will be easier.
    Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.

    Input

    You will be given a number of cases. The input for each case consists of one line of four integers p, e, i, and d. The values p, e, and i are the number of days from the beginning of the current year at which the physical, emotional, and intellectual cycles peak, respectively. The value d is the given date and may be smaller than any of p, e, or i. All values are non-negative and at most 365, and you may assume that a triple peak will occur within 21252 days of the given date. The end of input is indicated by a line in which p = e = i = d = -1.

    Output

    For each test case, print the case number followed by a message indicating the number of days to the next triple peak, in the form:

    Case 1: the next triple peak occurs in 1234 days.

    Use the plural form ``days'' even if the answer is 1.

    Sample Input

    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

    Sample Output

    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.

    题意:就是有3个值,给你3个时间(他们的峰值,但不一定是第一次的峰值),从d开始,到下一次3个值都是峰值,需要多少天(d不算);

    国剩余定理:(见注释);

    AC代码:

    
    
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<set>
    #include<map>
    #include<cctype>
    #include<algorithm>
    #define PI acos(-1.0)
    #define EPS 1e-8
    #include<cmath>
    using namespace std;
    int r1, r2, r3, r;
    
    void solve() {
        int i;//找到使两两取模为1 的 i,再乘
        for(i = 1, r1 = 23 * 28; ;i++) {
            if(r1*i % 33 == 1)
                break;
        }
        r1 *= i;
        for(i = 1, r2 = 23 * 33; ; i++) {
            if(r2*i % 28 == 1)
                break;
        }
        r2 *= i;
        for(i = 1, r3 = 28 * 33; ; i++) {
            if(r3*i % 23 == 1)
                break;
        }
        r3 *= i;
        r = 23*28*33;
    }
    
    int ii = 1;
    int main() {
        solve();
        int p, e, i, d, ans;
        while(~scanf("%d %d %d %d", &p, &e, &i, &d)) {
            if(p == -1)
                break;
            ans = (r1*i+r2*e+r3*p-d+r)%r;//注意不要乘错了(r1:23*28 所以再乘 33的余数)
            if(!ans)//特判
                ans = r;
            printf("Case %d: the next triple peak occurs in %d days.
    ", ii++, ans);
        }
    }
    
    
    
    
    
    
  • 相关阅读:
    nodejs安装autoprefixer
    nodejs安装Yui Compressor
    js捕捉回车事件
    支付宝服务窗前台页面规范
    html5 input type number 去掉加减号
    [USACO10HOL]赶小猪题解
    [USACO09FEB]改造路题解
    [HNOI2013]游走题解
    洛谷P1649 [USACO07OCT]障碍路线Obstacle Course BFS 最小转弯
    洛谷P1467 循环数 Runaround Numbers
  • 原文地址:https://www.cnblogs.com/ACMerszl/p/9572976.html
Copyright © 2011-2022 走看看