OpenJudge / Poj 1044 Date bugs C++
链接地址:
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
思路:
水题,简单遍历
代码:
#include <iostream>
#include <cstdio>
using namespace std; int main()
{
int n,i;
int count = ;
int temp_y;
scanf("%d",&n);
while(n!=)
{ int *arr_a = new int[n];
int *arr_b = new int[n];
int *arr_y = new int[n]; for(i =; i < n; i++) scanf("%d%d%d",&arr_y[i],&arr_a[i],&arr_b[i]);
temp_y = arr_y[];
while(temp_y < )
{
for(i = ;i < n; i++)
{
if((temp_y < arr_y[i]) || (temp_y - arr_y[i]) % (arr_b[i] - arr_a[i]) != ) break;
}
if(i >= n) break;
temp_y = temp_y + (arr_b[] - arr_a[]);
}
if(temp_y < ) printf("Case #%d: \nThe actual year is %d.\n",++count,temp_y);
else printf("Case #%d:\nUnknown bugs detected.\n",++count);
printf("\n"); delete [] arr_a;
delete [] arr_b;
delete [] arr_y; scanf("%d",&n);
}
return ;
}
OpenJudge / Poj 1044 Date bugs C++的更多相关文章
- POJ 1044: Date bugs
题目描述 There are rumors that there are a lot of computers having a problem with the year 2000. As they ...
- POJ1044 Date bugs
题目来源:http://poj.org/problem?id=1044 题目大意: 与众所周知的”千年虫“类似,某些计算机上存在日期记录的bug.它们的时钟有一个年份周期,每当到达最大值时,就会自动跳 ...
- OpenJudge / Poj 2141 Message Decowding
1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...
- OpenJudge/Poj 2105 IP Address
1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...
- OpenJudge/Poj 2027 No Brainer
1.链接地址: http://bailian.openjudge.cn/practice/2027 http://poj.org/problem?id=2027 2.题目: 总Time Limit: ...
- OpenJudge/Poj 2013 Symmetric Order
1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...
- OpenJudge/Poj 1088 滑雪
1.链接地址: bailian.openjudge.cn/practice/1088 http://poj.org/problem?id=1088 2.题目: 总Time Limit: 1000ms ...
- OpenJudge/Poj 2001 Shortest Prefixes
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...
- OpenJudge/Poj 2000 Gold Coins
1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...
随机推荐
- 网站WAF的检测
[wafw00f]: 项目地址: https://github.com/sandrogauci/wafw00f WAFW00F是识别和指纹Web应用防火墙(WAF)产品,其工作原理是首先通过发送一个正 ...
- PHP流程控制(二)
布尔型循环就是为真的时候执行,为假的时候停止 注意:1.循环能够节约大量的代码,提高重用性质2.循环,一定要有退出条件.3.While循环中,在while循环之前必须对变量进行初始化; 单层循环:语法 ...
- cocos2d-x中CCTextureCache图片资源的异步加载<转>
如果没有预先加载图片,则可以通过addImageAsync()函数实现异步加载,该函数通过创建一个加载线程来加载图片,并且在主线程中通过调用回调函数来读取该图片资源纹理.其主要过程如下: 1.创建线程 ...
- Tomcat无法部署项目
设置项目的Jdk,compire version 增加java EE 如果有必要,现在项目根目录下放置.mymetadata文件 <?xml version="1.0" en ...
- 主流数据库字段类型转.Net类型的方法
最近在阅读一些开源的代码,发现其中有些方法总结的很全面,至少在我做同样的事情时候,需要抓破脑袋想活着google,现在看到了这个关于主流数据库字段类型转.Net类型的方法,故收藏之,也顺便分享给那些能 ...
- android 处理网络状态——无网,2g,3g,wifi,ethernet,other
今天在一位很牛逼的学长的博客里面看到了这段代码后,很是激动啊,于是就“偷”了过来,嘿嘿....为自己也为更多需要它的程序媛 直接上代码: public class GetNetWorkStateAct ...
- OpenCV 显示Mat矩阵异常 显示“程序停止工作” 解决办法
笔者调试OpenCV 程序时,在使用标准输出显示Mat矩阵时,编译没有错误,但每次运行都弹出程序停止工作的对话框.google之,得到解决方案. 程序如下: #include <iostream ...
- 信号之alarm和pause函数
使用alarm函数可以设置一个计时器,在将来某个指定的时间,该计时器会超时.当计时器超时时,产生SIGALRM信号.如果不忽略或不捕捉此信号,则其默认动作是终止调用该alarm函数的进程. #incl ...
- 文件I/O(不带缓冲)之I/O的效率
程序清单3-3中的程序使用read和write函数复制文件.关于该程序应注意下列各点: 它从标准输入读,写至标准输出,这就假定在执行本程序之前,这些标准输入.输出已由shell安排好.确实,所有常用的 ...
- Jordan Lecture Note-7: Soft Margin SVM
Soft Margin SVM (1)Recall 之前分析到SVM的模型为: \begin{align}\mathop{\min}&\quad \frac{1}{2}w^\prime w\ ...