题目描述

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.

分析:毒瘤日期题,好好算,多调试。。。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int y[],a[],t[],n,cas;
void init(){ }
void solve(){
while(cin>>n,n){
range(i,,n-){
cin>>y[i]>>a[i]>>t[i];
t[i]-=a[i];
}
int ans=;
while((a[]=y[]+ans*t[])<){
bool flag=true;
range(i,,n-){
int tmp=a[]-y[i];
if(tmp<||tmp%t[i]){
flag=false;
break;
}
}
if(flag){
cout<<"Case #"<<++cas<<":"<<endl;
cout<<"The actual year is "<<a[]<<"."<<endl<<endl;
break;
}
++ans;
}
if(a[]>=){
cout<<"Case #"<<++cas<<":"<<endl;
cout<<"Unknown bugs detected."<<endl<<endl;
}
}
}
int main() {
init();
solve();
return ;
}

POJ 1044: Date bugs的更多相关文章

  1. OpenJudge / Poj 1044 Date bugs C++

    链接地址: Poj:http://poj.org/problem?id=1044 OpenJudge:http://bailian.openjudge.cn/practice/1044/ 题目: 总时 ...

  2. POJ1044 Date bugs

    题目来源:http://poj.org/problem?id=1044 题目大意: 与众所周知的”千年虫“类似,某些计算机上存在日期记录的bug.它们的时钟有一个年份周期,每当到达最大值时,就会自动跳 ...

  3. poj 2096 Collecting Bugs - 概率与期望 - 动态规划

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  4. POJ 2449Remmarguts' Date 第K短路

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 29625   Accepted: 8034 ...

  5. POJ 2096 Collecting Bugs 期望dp

    题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...

  6. 【CEOI2002】【Poj 1038】Bugs Integrated, Inc.

    http://poj.org/problem?id=1038 发一下中文题面(今天考试直接被改了): 生记茶餐厅由于受杀人事件的影响,生意日渐冷清,不得不暂时歇业.四喜赋闲在家,整天抱着零食看电视,在 ...

  7. POJ 2096 Collecting Bugs (概率DP,求期望)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

  8. POJ 2096 Collecting Bugs

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1716   Accepted: 783 C ...

  9. poj 2096 Collecting Bugs (概率dp 天数期望)

    题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...

随机推荐

  1. securecrt切换会话(session)的显示方式

    Window(窗口)-> Tabs(选项卡)/Tile Vertically(垂直平铺)/Tile Horizontally(水平平铺)/Cascade(瀑布,如下图效果)

  2. SQL多行变一列

    CREATE TABLE DEPT (DeptNo INT IDENTITY(1, 1)NOT NULL ,  Country VARCHAR(50) ,  Location VARCHAR(50) ...

  3. ADB连接手机遇到的问题:list of devices attached

    今天工作时想尝试一下使用ADB无线连接手机,结果遇到了下面这样的问题,浪费了几十分钟的时间,挺闹心的,因此想分享出来... 首先 第一步:使用USB数据线连接手机,手机弹出选项时,选择仅充电,然后wi ...

  4. 不吹不擂,你想要的Python面试都在这里了【315+道题】+精心整理的解答

    Part01-Py基础篇(80) Part02-网络编程和并发(34) Part03-数据库和缓存(46) Part04-前端框架和其他(155) Part01-Py基础篇(80) 1.为什么学习Py ...

  5. 第一次玩博客 感觉自己特别low

    第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动第一天来  来好激动 ...

  6. Linux自学系列 -- 常用指令的使用

    1.查看目录下内容>ls //列出目录下的文件信息>ls -l      //以“详细信息"查看目录文件>ls -a     //查看目录“全部”(包括隐藏文件)文件> ...

  7. Oracle 数据库导出时 EXP-00008;ORA-00904

    问题是客户端和服务器端版本问题,我本地是11g,而服务器端是10g. 规则1:低版本的exp/imp可以连接到高版本(或同版本)的数据库服务器,但高版本的exp/imp不能连接到低版本的数据库服务器. ...

  8. CodeForces Round #515 Div.3 D. Boxes Packing

    http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size e ...

  9. BI商业智能培训系列——(一)概述

    简介: Business Intelligence,简称 BI. 商业智能,是指用现代的技术进行数据分析,以实现商业价值,这些技术包括数据仓库技术,线上分析处理技术,数据挖掘,数据展现技术等. 以往的 ...

  10. [CF191C]Fools and Roads

    题目大意:有一颗$n$个节点的树,$k$次旅行,问每一条被走过的次数. 题解:树上差分,$num_x$表示连接$x$和$fa_x$的边被走过的次数,一条路径$u->v$,$num_u+1,num ...