Date bugs

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3005   Accepted: 889

Description

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 .

Input

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.

Output

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.

Sample Input

  1. 2
  2. 1941 1900 2000
  3. 2005 1904 2040
  4. 2
  5. 1998 1900 2000
  6. 1999 1900 2000
  7. 0

Sample Output

  1. Case #1:
  2. The actual year is 2141.
  3.  
  4. Case #2:
  5. Unknown bugs detected.

Source

题目大意:
有一个日期BUG,给定日期a和b,当日期超过b时就从a开始算起。现在给定日期y a b分别代表按照错误算法的年份y,a为最小年份,b为最大年份。
思路:
由于第一次写博客,先挑一个水题尝试的写一下,写的不好的地方请大家见谅。本题有一个限定条件是查找的年份大于10000时,就输出"Unknown bugs detected.",这样我们直接遍历就可以了。讲讲我的代码思路吧,因为题目限制了最大的年份为10000,所以我开一个10000的数组(只要大于10000就行),将可能结果存起来,num[i]=k,其中i表示年份的可能值,k表示出现的次数。最后遍历1~10000,查出数组出现次数和给定的实例都符合则找到该正确的年份,反之亦反。最后大家直接看代码就可以,Poj上面做题主要就是注意格式和一些优化。
  1. import java.util.Scanner;
  2. public class Main{
  3. static int MAX = 10000;
  4. public static void main(String[] arg){
  5. Scanner scanner = new Scanner(System.in);
  6. int count = 1;
  7. while(scanner.hasNext()){
  8. int n = scanner.nextInt();
  9. int []num = new int[MAX];//可能为正确年份的数
  10. boolean flag = false;
  11. if(n==0)break;
  12. else{
  13. for(int i=0;i<MAX;i++)num[i]=0;
  14. for(int i=0;i<n;i++){//给定bug实例个数
  15. int y = scanner.nextInt();
  16. int a = scanner.nextInt();
  17. int b = scanner.nextInt();
  18. for(int j=y;j<MAX;j=j+b-a){
  19. num[j]++;
  20. }
  21. }
  22. flag = false;
  23. for(int i=0;i<MAX;i++){
  24. if(num[i]==n){
  25. System.out.print("Case #"+count+":\n"+"The actual year is "+i+".\n\n");
  26. flag = true;
  27. break;
  28. }
  29. }
  30. if(flag==false){
  31. System.out.print("Case #"+count+":\n"+"Unknown bugs detected.\n\n");
  32. }
  33. }
  34. count++;
  35. }
  36. }
  37.  
  38. }
 
 

第一次写博客Poj1044的更多相关文章

  1. 第一次写博客,关于前端开发deMVC在js中的应用

    对前端MVC MVC分别是model.view.controller的缩写,模型.视图.控制器.这些更加偏向于后台,在以前MVC是只属于后台的.当然随着技术的进步,前端的大牛们将后台的一些东西应用于前 ...

  2. HDU 2064 菜鸡第一次写博客

    果然集训就是学长学姐天天传授水铜的动态规划和搜索,今天讲DP由于困意加上面瘫学长"听不懂就是你不行"的呵呵传授,全程梦游.最后面对连入门都算不上的几道动态规划,我的内心一片宁静,甚 ...

  3. 第一次写博客,就写如何向外行介绍自己做的是什么,那个我是做web的

    如果想外行问你是做什么的,改如何回答.和内行说java后台就可以了,但外行听不懂,我们该如何描述呢? 我的方法是:我做的是java web开发,不是内外的外,是个英文单词web,全名叫world wi ...

  4. iOS controller解耦探究实现——第一次写博客

    大学时曾经做过android的开发,目前的工作是iOS的开发.之前自己记录东西都是通过自己比较喜欢的笔记类的应用记录下了.直到前段时一个哥们拉着我注册了一个博客.现在终于想明白了,博客这个东西受众会稍 ...

  5. Magazine Ad CodeForces - 803D(二分 + 贪心,第一次写博客)

    Magazine Ad The main city magazine offers its readers an opportunity to publish their ads. The forma ...

  6. 谈谈自己对C语言中函数指针的一些理解 (第一次写博客,有点小兴奋哈)

    1.函数指针声明的格式及简单的使用 (1)格式:(返回值)(*函数指针名)(参数列表)    例如:声明一个无参数无返回值的函数指针(void)(*p)(void). (2)将函数指针指向某个无参数无 ...

  7. sikuli+eclipse对于安卓app自动化测试的应用(第一次写博客,有些语言还不太专业,望海涵)

    Sikuli是什么? 下面是来自于官网的介绍:Sikuli is a visual technology to automate and test graphical user interfaces ...

  8. ViewPager实现自动翻页功能 --转载出处找不到了,根据自己的理解写个随笔方便以后的记忆以及代码的共享,感谢给我启发的那位高手--第一次写博客哈

    xml文件 textview 用于显示图片的标题 viewpager 用于实现翻页效果 <LinearLayout xmlns:android="http://schemas.andr ...

  9. 写一下SPFA和迪杰斯特拉的模版。。。第一次写博客,有错请提出哦!

    SPFA的模版 #include<bits/stdc++.h> using namespace std; queue <int> q; typedef pair <int ...

随机推荐

  1. 使用yield进行异步流程控制

    现状 目前我们对异步回调的解决方案有这么几种:回调,deferred/promise和事件触发.回调的方式自不必说,需要硬编码调用,而且有可能会出现复杂的嵌套关系,造成"回调黑洞" ...

  2. 1Z0-053 争议题目解析486

    1Z0-053 争议题目解析486 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 486.You execute the following Recovery Manager (R ...

  3. Sybase数据库,普通表修改分区表步骤

    本文目标:指导项目侧人员再遇到此类改动需求时可以自己参照更改.需求:Sybase数据库,普通表t_jingyu修改为按天分区的分区表. 1.sp_help查看t_jingyu的表结构,索引等信息 sp ...

  4. Ubuntu下搭建ryu环境

    RYU环境搭建总共四步: step1:首先下载相应的python套件,并且更新pip $ sudo apt-get install python-pip python-dev build-essent ...

  5. 解析ActionResult子类JsonResult

    前言 MVC我是11开始使用的,当时还是在上地软件园一小型互联网公司,当时是MVC2.0+Linq to sql.后来接着学习MVC3,MVC3的出现确实让我有种眼前一亮的感觉,期间我不断的写各种de ...

  6. OpenCV2:图像的几何变换,平移、镜像、缩放、旋转(2)

    在OpenCV2:图像的几何变换,平移.镜像.缩放.旋转(1)主要介绍了图像变换中的向前映射.向后映射.处理变换过程中浮点坐标像素值的插值算法,并且基于OpenCV2实现了两个简单的几何变换:平移和镜 ...

  7. 7.9 数据注解特性--ForeignKey

    外键特性,可以应用到类的属性中.Code-First默认的约定,对外键属性来说,假定外键属性的名称和主键属性是匹配的. 我们看一下,下面的代码: using System; using System. ...

  8. 百度编辑器UEditor常用设置函数大全

    在线文档对UEditor说明不够全面,收集了一些常用的方法和基本设置,以供参考.1.创建编辑器UE.getEditor('editor', { initialFrameWidth:"100% ...

  9. 【Java每日一题】20161220

    package Dec2016; public class Ques1220 { public static void main(String[] args) { Integer num1 = new ...

  10. No.008:String to Integer (atoi)

    问题: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...