poj 1676 What time is it?(经典模拟)

题目:http://poj.org/problem?id=1676

What time is it?
Time Limit: 1000MS   Memory Limit: 10000K
Total 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.

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 Sure
0825
分析:刚开始没有思路,参照了别人的代码。。将那些字符图案转化为二进制存储,3行字符信息变成1行数字信息,然后暴力分析即可,如果有多个或者没有满足条件的预测时间,那么就是Not sure,否则输出时间。具体见下:
/*
对照字符图案,将数字转化成二进制:
0--> 010 101 111
1--> 000 001 001
2--> 010 011 110
3--> 010 011 011
4--> 000 111 001
5--> 010 110 011
6--> 010 110 111
7--> 010 001 001
8--> 010 111 111
9--> 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;
}


你可能感兴趣的:(poj,暴力)