免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1510 | 回复: 4
打印 上一主题 下一主题

这道题我为什么错了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-10-03 23:03 |只看该作者 |倒序浏览
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>
#define MAX 500
int main()
{
int p[MAX],i[MAX],e[MAX],d[MAX],x[MAX],j=-1,k,a,c;
do
{
     j++;
     scanf("%d %d %d %d",&p[j],&i[j],&e[j],&d[j]);
  }while(p[j]>-1&&i[j]>-1&&e[j]>-1&&d[j]>-1);
for(k=0;k<j;k++)
{
     x[k]=0;
  for(a=1;a<=28;a++)
  {
   if(((23*a)%28+(p[k]-i[k])%28)%28==0)
    {
      x[k]=23*a+x[k];
      break;
     }
    }
  for(c=0;c<=33;c++)
   if(((23*(a+28*c))%33+(p[k]-e[k])%33)%33==0)
   {
     x[k]=23*(a+28*c)+p[k];
     break;
    }
  x[k]=x[k]-d[k];
}
for(k=0;k<j;k++)
  printf("Case %d: the next triple peak occurs in %d days.\n",k+1,x[k]);
return 0;
}

论坛徽章:
0
2 [报告]
发表于 2006-10-04 18:44 |只看该作者
用给出的数据代入,你的程序得出的结果正确吗?

论坛徽章:
0
3 [报告]
发表于 2006-10-04 18:45 |只看该作者

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>

  4. using namespace std;

  5. int main()
  6. {
  7.         vector<int> physicalPeak, emotionalPeak, intellectualPeak, startDay;
  8.         const int pcycle = 23, ecycle = 28, icycle = 33;       
  9.         int p, e, i, d;
  10.         do{
  11.                 cin >> p >> e >> i >> d;
  12.                 physicalPeak.push_back(p);
  13.                 emotionalPeak.push_back(e);
  14.                 intellectualPeak.push_back(i);
  15.                 startDay.push_back(d);
  16.         }while(p != -1 && e != -1 && i != -1 && d != -1);

  17.         for (unsigned i = 0; i < physicalPeak.size() - 1; ++i) {
  18.                 int start = startDay[i] + 1;
  19.                 start = max(start, physicalPeak[i]);
  20.                 start = max(start, emotionalPeak[i]);
  21.                 start = max(start, intellectualPeak[i]);

  22.                 for (int j = start; j < 21252; ++j) {
  23.                         if ((j - physicalPeak[i]) % pcycle == 0
  24.                                 && (j - emotionalPeak[i]) % ecycle == 0
  25.                                 && (j - intellectualPeak[i]) % icycle == 0)
  26.                                 break;
  27.                 }

  28.                 cout << "Case " << (i + 1) << ": the next triple peak occurs in " << (j - startDay[i]) << "days.\n";
  29.         }  
  30. }
复制代码

论坛徽章:
0
4 [报告]
发表于 2006-10-05 21:33 |只看该作者
想当年,这道题我也老是错。。唉,当年的ACM

论坛徽章:
0
5 [报告]
发表于 2006-10-06 21:25 |只看该作者
看不懂啊,对C++不是很懂
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP