荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: kaman (天外飞仙), 信区: ACMICPC
标  题: [合集]帮我看看这题吧,老是WA,真受不了
发信站: 荔园晨风BBS站 (Mon May  3 14:25:25 2004), 站内信件

bakey (飘云) 于Fri Apr 30 21:09:11 2004提到:

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.

bakey (飘云) 于Fri Apr 30 21:09:48 2004提到:

我的代码
#include <stdio.h>
int main()
{
        int x,p,e,i,d,day,j=0;
        while (1)
        {
                scanf("%d%d%d%d",&p,&e,&i,&d);
                j++;
                if ((p==-1)&&(e==-1)&&(i==-1)&&(d==-1))
                        break;
                else
                        for (x=d+1;x<=21252;x++)
                        {
                                if (((x-p)%23==0)&&((x-e)%28==0)&&((x-i)%33==0))
                                        break;
                        }
                        if (x==0)
                                printf("Case %d: the next triple peak occurs in
21252 days.\n",j);
                        else
                        {
                                day=x-d;
                                printf("Case %d: the next triple peak occurs in
%d days.\n",j,day);

                        }
        }
        return 0;
}


alec (AlecMonkeyKing) 于Fri Apr 30 21:16:38 2004提到:

同余方程
btw: who are you?


bakey (飘云) 于Fri Apr 30 21:47:41 2004提到:

算法方面应该没什么问题的,不过不知是不是有什么情况没有


huhaiming (一生只爱她) 于Fri Apr 30 21:49:30 2004提到:

建议你看了中国剩余定理后再来做这题



alec (AlecMonkeyKing) 于Fri Apr 30 22:17:50 2004提到:

i am lazy to read your code
just tell me what's your algorithm


bakey (飘云) 于Fri Apr 30 22:28:52 2004提到:

从d+1开始寻找数字x,x<=21252(题目规定),找到的x减去p,e,i。得到的三个数
应该满足分别
%23%28%33都等于0.最后输出x-d。考虑到特殊情况:p,e,i,d都等于0的话,就输出
21252~~~~

看什么看???没见过不会做签名档的人啊

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.111.149]
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.111.149]

alec (AlecMonkeyKing) 于Fri Apr 30 22:29:24 2004提到:

wait....
reading your code


kaman (天外飞仙) 于Fri Apr 30 22:32:27 2004提到:

标准的剩余问题了~



alec (AlecMonkeyKing) 于Fri Apr 30 22:35:58 2004提到:

try search from d to 21252


huhaiming (一生只爱她) 于Fri Apr 30 22:37:18 2004提到:

也许你会找到的数大于21252,你需要减去一个周期
譬如,如果你找到的x

if(x>21252)  x-=21252;


bakey (飘云) 于Fri Apr 30 22:38:35 2004提到:

看什么看???没见过不会做签名档的人啊

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.111.149]
※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.111.149]

huhaiming (一生只爱她) 于Fri Apr 30 22:43:13 2004提到:

在网上或者自己找书看看剩余定理

然后看明白我写的程序

//Zju 1160
//By Jhun
//On Thursday May 23th

#include <stdio.h>

int main()
{
        int n,p,e,i,d,temp,count;

        scanf("%d",&n);
        for(int j=1;j<=n;j++)
        {
                count=0;
                while(1)
                {
                        scanf("%d%d%d%d",&p,&e,&i,&d);
                        if (p==-1) break;
                        count++;
                        temp=(p*6*28*33+e*19*23*33+i*2*23*28)%21252;
                        temp-=d;
                        if (temp<=0) temp=21252+temp;
      printf("Case %d: the next triple peak occurs in %d days.\n",count,temp);
                }
                if (j<n) printf("\n");
        }
        return 0;
}



alec (AlecMonkeyKing) 于Fri Apr 30 22:45:28 2004提到:

{
}


bakey (飘云) 于Fri Apr 30 22:48:09 2004提到:

搜索的范围是少于21252的。不过这样我又想到了,如果在这个范围内找不到
合适的数要怎么处理呢?题目没说得清楚。它说:You may assume that a
triple peak will occur within 21252 days of the given date.不知在


alec (AlecMonkeyKing) 于Fri Apr 30 22:50:13 2004提到:

不肯能的


bakey (飘云) 于Fri Apr 30 22:50:22 2004提到:

看第一个sample input/output 那里啊,我是照样推出来的


bakey (飘云) 于Fri Apr 30 22:53:05 2004提到:



huhaiming (一生只爱她) 于Fri Apr 30 22:57:54 2004提到:

i can surely tell you! 这样的数据是有的


alec (AlecMonkeyKing) 于Fri Apr 30 23:16:06 2004提到:

first, read the problem carefuly!
about the input.

#include <stdio.h>
int main()
{
        int x,p,e,i,d,day,j=0,kk,k;
                scanf("%d",&kk);
                for (k=0;k<kk;k++)
                {
                        j=0;
        while (1)
        {

                scanf("%d%d%d%d",&p,&e,&i,&d);
                j++;
                if ((p==-1)&&(e==-1)&&(i==-1)&&(d==-1))
                        break;
                else
                                {
                        for (x=d+1;x<=21252000;x++)
                        {
                                if (((x-p)%23==0)&&((x-e)%28==0)&&((x-i)%33==0))
                                        break;
                        }
                                }
                                 day=(x%21252)-d;
                                                                 if (day<=0)

day=day+21252;
                                printf("Case %d: the next triple peak occurs in
%d days.\n",j,day);


        }
                if (k+1<kk)
                        printf("\n");
                }
        return 0;
}



alec (AlecMonkeyKing) 于Fri Apr 30 23:16:21 2004提到:

use your method


bakey (飘云) 于Fri Apr 30 23:19:09 2004提到:



huhaiming (一生只爱她) 于Fri Apr 30 23:20:49 2004提到:

你可以测测的嘛


alec (AlecMonkeyKing) 于Fri Apr 30 23:20:49 2004提到:

never mind, just have a look on your fixed code


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店