OpenJudge / Poj 1044 Date bugs C++

本文介绍了一个关于Y2K问题的程序设计题目,包括问题背景、输入输出要求及示例。通过简单的遍历算法找到最早可能的真实年份。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接地址:

Poj:http://poj.org/problem?id=1044

OpenJudge:http://bailian.openjudge.cn/practice/1044/

题目:

总时间限制:
1000ms
内存限制:
65536kB
描述
There are rumors that there are a lot of computers having a problem with the year 2000. As they use only two digits to represent the year, the date will suddenly turn from 1999 to 1900. In fact, there are also many other, similar problems. On some systems, a 32-bit integer is used to store the number of seconds that have elapsed since a certain fixed date. In this
way, when 2^32 seconds (about 136 Years) have elapsed, the date will jump back to whatever the fixed date is.
Now, what can you do about all that mess? Imagine you have two computers C1 and C with two different bugs: One with the ordinary Y2K-Bug (i. e. switching to a1 := 1900 instead of b1 := 2000) and one switching to a2 := 1904 instead of b2 := 2040. Imagine that the C1 displays the year y1 := 1941 and C2 the year y2 := 2005. Then you know the following (assuming that there are no other bugs): the real year can't be 1941, since, then, both computers would show the (same) right date. If the year would be 2005, y1 would be 1905, so this is impossible, too. Looking only at C1 , we know that the real year is one of the following: 1941, 2041, 2141, etc. We now can calculate what C2 would display in these years: 1941, 1905, 2005, etc. So in fact, it is possible that the actual year is 2141.
To calculate all this manually is a lot of work. (And you don't really want to do it each time you forgot the actual year.) So, your task is to write a program which does the calculation for you: find the first possible real year, knowing what some other computers say (yi) and knowing their bugs (switching to ai instead of bi ). Note that the year ai is definitely not after the year the computer was built. Since the actual year can't be before the year the computers were built, the year your program is looking for can't be before any ai .
输入
The input file contains several test cases, in which the actual year has to be calculated. The description of each case starts with a line containing an integer n (1 <= n <= 20), the number of computers. Then, there is one line containing three integers yi,ai,bi for each computer (0 <= ai <= yi < bi < 10000). yi is the year the computer displays, bi is the year in which the bug happens (i. e. the first year which can't be displayed by this computer) and ai is the year that the computer displays instead of bi .
The input is terminated by a test case with n = 0. It should not be processed.
输出
For each test case, output output the line "Case #k:", where k is the number of the situation. Then, output the line "The actual year is z.", where z is the smallest possible year (satisfying all computers and being greater or equal to u). If there is no such year less than 10000, output "Unkown bugs detected.". Output a blank line after each case.
样例输入
2 
1941 1900 2000 
2005 1904 2040 
2 
1998 1900 2000 
1999 1900 2000 
0 
样例输出
Case #1: 
The actual year is 2141. 

Case #2: 
Unknown bugs detected. 
来源
Mid-Central European Regional Contest 1999

思路:

水题,简单遍历

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int n,i;
 8     int count = 0;
 9     int temp_y;
10     scanf("%d",&n);
11     while(n!=0)
12     {
13 
14 
15         int *arr_a = new int[n];
16         int *arr_b = new int[n];
17         int *arr_y = new int[n];
18 
19         for(i =0; i < n; i++) scanf("%d%d%d",&arr_y[i],&arr_a[i],&arr_b[i]);
20         temp_y = arr_y[0];
21         while(temp_y < 10000)
22         {
23             for(i = 1;i < n; i++)
24             {
25                 if((temp_y < arr_y[i]) || (temp_y - arr_y[i]) % (arr_b[i] - arr_a[i]) != 0) break;
26             }
27             if(i >= n) break;
28             temp_y = temp_y + (arr_b[0] - arr_a[0]);
29         }
30         if(temp_y < 10000) printf("Case #%d: \nThe actual year is %d.\n",++count,temp_y);
31         else printf("Case #%d:\nUnknown bugs detected.\n",++count);
32         printf("\n");
33 
34         delete [] arr_a;
35         delete [] arr_b;
36         delete [] arr_y;
37 
38         scanf("%d",&n);
39     }
40     return 0;
41 }

 

转载于:https://www.cnblogs.com/mobileliker/p/3512980.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值