| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:北大acm题Biorhythms
只看楼主 加入收藏
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
结帖率:100%
收藏
 问题点数:0 回复次数:8 
北大acm题Biorhythms
Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 71   Accepted Submission(s) : 23
Problem 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.
我的代码:

 #include <stdio.h>
int main()
{
    int p,e,i,d,l,n=0;
    while(scanf("%d %d %d %d",&p,&e,&i,&d)!=EOF)
    {
    if(p==-1&&e==-1&&i==-1&&d==-1)
        return 0;
    n++;   for(l=1;!((l-p)%23==0&&(l-e)%28==0&&(l-i)%33==0);l++);
 if(p==e&&e==i&&d>=p)
    printf("Case %d: the next triple peak occurs in %d days.\n",n,21252-(d-p));
  else  printf("Case %d: the next triple peak occurs in %d days.\n",n,l-d);
    }
}
为何提交wrong answer
搜索更多相关主题的帖子: emotional physical believe periods person 
2014-03-28 11:03
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
最起码 scanf("%d %d %d %d",&p,&e,&i,&d)!=EOF 就不对,题目明明说说的是 -1 -1 -1 -1 为输入结束
2014-03-28 11:51
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
收藏
得分:0 
回复 2楼 rjsp
程序没怎么好好修改,有些地方可能写的多余,但确实是-1 -1 -1 -1结束,下面有这个判断return 0,我主要是想知道是不是有些特例,题目样例运行都正确,不知道错在哪里
2014-03-28 12:34
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
以下是引用pavilion4994在2014-3-28 12:34:17的发言:

程序没怎么好好修改,有些地方可能写的多余,但确实是-1 -1 -1 -1结束,下面有这个判断return 0,我主要是想知道是不是有些特例,题目样例运行都正确,不知道错在哪里
为什么要将循环判断语句硬生生拆掉一半移到循环体内?算了,不管了。

我随便输入两句
21252 21252 21252 21252
23 28 33 21252
你的输出是
the next triple peak occurs in 0 days.
the next triple peak occurs in 0 days.
2014-03-28 12:56
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
程序代码:
#include <stdio.h>

int main()
{
    for( int p,e,i,d,n=1; scanf("%d %d %d %d",&p,&e,&i,&d)==4 && p!=-1 && e!=-1 && i!=-1; ++n )
    {
        int x = ((28*33*6)*p + (23*33*19)*e + (23*28*2)*i)%(23*28*33) - d%(23*28*33);
        if( x <= 0 )
            x += (23*28*33);
        printf( "Case %d: the next triple peak occurs in %d days.\n", n, x );
    }
   

    return 0;
}
2014-03-28 13:15
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
收藏
得分:0 
回复 5楼 rjsp
非常感谢,但题目要求输入在365内,按照我的枚举的方法结果好像与你的一样,还是不知道自己写的错在哪里,望解答
2014-03-28 13:43
Alar30
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:10
帖 子:988
专家分:1627
注 册:2009-9-8
收藏
得分:0 
那家伙
非科班出身
看着像天书啊。。。
2014-03-28 14:20
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
以下是引用pavilion4994在2014-3-28 13:43:10的发言:

非常感谢,但题目要求输入在365内,按照我的枚举的方法结果好像与你的一样,还是不知道自己写的错在哪里,望解答
对于
if(p==e&&e==i&&d>=p)
    printf("Case %d: the next triple peak occurs in %d days.\n",n,21252-(d-p));
  else  printf("Case %d: the next triple peak occurs in %d days.\n",n,l-d);
我总觉得挺怪的,l-d 我明白,那么 if 就应该是 if( l <= d ),要不你将代码改为
        if( l <= d )
            printf( "Case %d: the next triple peak occurs in %d days.\n", n, 21252+l-d );
        else
            printf( "Case %d: the next triple peak occurs in %d days.\n", n, l-d);
试试看

或者,别烦l和d的大小了,直接
for(l=1;!((l+d-p)%23==0&&(l+d-e)%28==0&&(l+d-i)%33==0);l++);
printf( "Case %d: the next triple peak occurs in %d days.\n", n, l );

2014-03-28 16:28
pavilion4994
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2013-10-17
收藏
得分:0 
回复 8楼 rjsp
很感谢,通过了,不过总感觉在365范围内找不到l<d情况
2014-03-28 21:04
快速回复:北大acm题Biorhythms
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036227 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved