poj 1676 What time is it?(经典模拟)
来源:互联网 发布:中原g7 知乎 编辑:程序博客网 时间:2024/05/22 14:05
题目:http://poj.org/problem?id=1676
What time is it?
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1483 Accepted: 578
Description
An accutron shows time with four digits, from 0000 to 2359. Every digit is represented by 3*3 characters, including '|'s, '_'s and blanks. When the LCD screen works well, the digits look like the following:
There are two accutrons at hand. One shows the accurate time, and the other is 15 minutes late. For example, at 8:25am, the first accutron shows '0825', while the second shows '0810'.
Unfortunately, there is something wrong with the two LCD screens, namely some parts of the digits missed. Your task is to decide the accurate time, according to the fragmental digits showed on the two accutrons.
_ _ _ _ _ _ _ _ | | | _| _||_||_ |_ ||_||_||_| ||_ _| | _||_| ||_| _|
There are two accutrons at hand. One shows the accurate time, and the other is 15 minutes late. For example, at 8:25am, the first accutron shows '0825', while the second shows '0810'.
Unfortunately, there is something wrong with the two LCD screens, namely some parts of the digits missed. Your task is to decide the accurate time, according to the fragmental digits showed on the two accutrons.
Input
The first line of the input is a single integer t (1 <= t <= 20), the number of test cases. Each case contains three lines, indicating the time on the accurate accutron and the time on the slow accutron, separated by a blank column. (Please refer to the Sample Input.)
Output
For each input, print the accurate time with four digits if it can be ensured, or otherwise the string 'Not Sure'.
Sample Input
2 _ _ _ _ _ | _ _|| _ || | _ |_ | | _ |_| _ _ _ _ _ _ ||_ _|| _| || | _ |_ | || |_|
Sample Output
Not Sure0825分析:刚开始没有思路,参照了别人的代码。。将那些字符图案转化为二进制存储,3行字符信息变成1行数字信息,然后暴力分析即可,如果有多个或者没有满足条件的预测时间,那么就是Not sure,否则输出时间。具体见下:
/*对照字符图案,将数字转化成二进制:0--> 010 101 1111--> 000 001 0012--> 010 011 1103--> 010 011 0114--> 000 111 0015--> 010 110 0116--> 010 110 1117--> 010 001 0018--> 010 111 1119--> 010 111 011*/#include <iostream>#include <cstdio>using namespace std;#define rep(i, n) for(int i = 0; i < n; i++)#define repf(i, a, b) for(int i = a; i <= b; i++)const int digit[10][9] = { {0, 1, 0, 1, 0, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 1, 0, 0, 1}, {0, 1, 0, 0, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 1, 1, 0, 1, 1}, {0, 0, 0, 1, 1, 1, 0, 0, 1}, {0, 1, 0, 1, 1, 0, 0, 1, 1}, {0, 1, 0, 1, 1, 0, 1, 1, 1}, {0, 1, 0, 0, 0, 1, 0, 0, 1}, {0, 1, 0, 1, 1, 1, 1, 1, 1}, {0, 1, 0, 1, 1, 1, 0, 1, 1} };int first[5][10]; //一维:第几个数字; 二维:一行的长度int second[5][10];char buf[25];bool judge_first(int h, int m){ int x = h / 10; rep(i, 9) { if(first[0][i] == 1 && digit[x][i] == 0) return false; } x = h % 10; rep(i, 9) { if(first[1][i] == 1 && digit[x][i] == 0) return false; } x = m / 10; rep(i, 9) { if(first[2][i] == 1 && digit[x][i] == 0) return false; } x = m % 10; rep(i, 9) { if(first[3][i] == 1 && digit[x][i] == 0) return false; } return true;}bool judge_second(int h, int m){ int x = h / 10; rep(i, 9) { if(second[0][i] == 1 && digit[x][i] == 0) return false; } x = h % 10; rep(i, 9) { if(second[1][i] == 1 && digit[x][i] == 0) return false; } x = m / 10; rep(i, 9) { if(second[2][i] == 1 && digit[x][i] == 0) return false; } x = m % 10; rep(i, 9) { if(second[3][i] == 1 && digit[x][i] == 0) return false; } return true;}int main(){ //freopen("cin.txt","r",stdin); int t; scanf("%d", &t); getchar(); while(t--) { rep(i, 3) { gets(buf); rep(j, 12) { if(buf[j] == '_' || buf[j] == '|') first[j / 3][i * 3 + j % 3] = 1; else first[j / 3][i * 3 + j % 3] = 0; } repf(j, 13, 24) { if(buf[j] == '_' || buf[j] == '|') second[(j - 1) / 3 - 4][i * 3 + (j - 1) % 3] = 1; else second[(j - 1) / 3 - 4][i * 3 + (j - 1) % 3] = 0; } } int h = -1, m = -1,sum=0; rep(i, 24) { rep(j, 60) { if(judge_first(i, j)) { int x = i; int y = j - 15; if(y < 0) { y += 60; x--; if(x < 0) x = 23; } if(judge_second(x, y)) { sum++; h = i; m = j; } } } } if(sum != 1) printf("Not Sure\n"); else printf("%02d%02d\n", h, m);//%02d 前的0不能丢,不足补齐0 } return 0;}
0 0
- poj 1676 What time is it?(经典模拟)
- Poj 1676 What time is it?
- poj 1676 What time is it?
- poj 1676-What time is it?
- poj 1676 What time is it?
- POJ 1676 What time is it? 笔记
- what time is it?
- poj1676 What time is it?
- Problem 45 What Time Is It
- HDU2133 What day is it 模拟题
- What Day Is It?(模拟)
- What is time meaning......
- what is time
- what is Time Management?
- Maven... What is it?
- what fuck it is
- What is aliasing and what causes it?
- HDU2133:What day is it
- UVa 12325:Zombie's Treasure Chest(暴力)
- 模板方法
- web_reverse_proxy --> haproxy
- 《基于GTK的USB视频采集程序》
- 项目风险管理
- poj 1676 What time is it?(经典模拟)
- 学习java与思维导图
- NYOJ--102--次方求模
- 程序员读书和练习的方法(个人观点)
- 第96讲:Akka第一个案例动手实战main方法实现中ActorSystem等代码详解学习笔记
- iOS开发:通讯录之联系人添加、移动、删除
- AdaultBird--我的黑马程序员之路!Chapter3---多线程同步,同步唤醒和等待,守护线程,String类,基本数据类型包装类,集合框架中的List和Set
- 欢迎使用CSDN-markdown编辑器
- populate next right pointer in each node