ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

BLMOOC4148生理周期

2019-08-05 19:43:33  阅读:285  来源: 互联网

标签:周期 int days BLMOOC4148 result triple 生理 next occurs


总时间限制:

1000ms

内存限制:

65536kB

描述

人生来就有三个生理周期,分别为体力周期、感情周期和智力周期,它们的周期长度分别为23天、28天和33天。每一个周期中有一天是高峰。在高峰这天,人会在相应的方面表现出色。例如,在智力周期的高峰,人会思维敏捷,注意力容易高度集中。因为三个周期的长度不同,所以通常三个周期的高峰不会落在同一天。对于每个人,想知道何时三个高峰落在同一天。对于每个周期,会给出从当前年份的第一天开始,到出现高峰的天数(不一定是第一次高峰出现的时间)。给定一个从当年第一天开始的天数,你的任务是输出从给定时间开始(不包括给定时间),下一次三个高峰落在同一天的时间(距给定时间的天数)。例如:给定时间为10,下次出现三个高峰同一天的时间是12,则输出2(注意这里不是3)。

输入

输入包含多组数据,每一组数据由四个整数组成,数据以-1 -1 -1 -1 结束。
对于四个整数p, e, i和d,p, e, i分别表示体力、情感和智力高峰出现的时间(时间从当年的第一天开始计算)。d是给定的时间,可能小于p, e或i。所有给定时间是非负的并且小于或等于365,所求的时间小于或等于21252。

输出

从给定时间起,下一次三个高峰同一天的时间(距离给定时间的天数)。

样例输入

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.

一开始的思路(错误):

#include<bits/stdc++.h>
using namespace std;
int main(){
    int p,e,i,d,t=0;
    while(scanf("%d %d %d %d",&p,&e,&i,&d)&&p!=-1){
        t++;
        int result=0;
        for(result=i;;result+=33){
            if(!(result-e)%28)continue;
            for(;;result+=28)
                if(!(result-p)%23)continue;
        }
        printf("Case %d: the next triple peak occurs in %d days.\n",t,result);
    }
    return 0;
}

第一次尝试(WA):因为三个if判断语句中不能写成!,写成==0就对了

#include<bits/stdc++.h>
using namespace std;
int main(){
    int p,e,i,d,t=0;
    while(scanf("%d %d %d %d",&p,&e,&i,&d)&&p!=-1){
        t++;
        int result=d+1;
        for(;result<21252;result++)
            if(!(result-i)%33)break;
        for(;result<21252;result+=33)
            if(!(result-e)%28)break;
        for(;result<21252;result+=28*33)
            if(!(result-p)%23)break;
        printf("Case %d: the next triple peak occurs in %d days.\n",t,result-d);
    }
    return 0;
}

AC:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int p,e,i,d,t=0;
    while(scanf("%d %d %d %d",&p,&e,&i,&d)&&p!=-1){
        t++;
        int result=d+1;
        for(;result<21252;result++)
            if((result-i)%33==0)break;
        for(;result<21252;result+=33)
            if((result-e)%28==0)break;
        for(;result<21252;result+=28*33)
            if((result-p)%23==0)break;
        printf("Case %d: the next triple peak occurs in %d days.\n",t,result-d);
    }
    return 0;
}

 

标签:周期,int,days,BLMOOC4148,result,triple,生理,next,occurs
来源: https://blog.csdn.net/ur_ytii/article/details/98508438

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有