URAL 2081 Faulty dial

 题目:

              Faulty dial

Pavel has not played ACM for ages, nor does he train teams, nor prepare problems. The thing is that there are much more global issues that concern him — Pavel ponders on education as a whole. His thoughts are always busy with this, but the problem is that various insignificancies distract him all the time! Let us look at a microwave oven, for example. Firstly, it does not allow to set exact time in seconds for warming up food, whilst seconds play the key role in this issue! That is why Pavel has to set the minimal available time option exceeding the time needed, and to keep an eye on the timer in order to switch the oven off at the right moment. Secondly, as it came out, the oven’s dial is faulty — random digit segments may be not displayed when indicating time. As a result it becomes nearly impossible to stop the oven at the correct moment of time — with faulty dial Pavel is unable to read what the timer is displaying at each moment.
Help Pavel — write a program recovering real timer data.

Input

The first line contains n (1 ≤ n ≤ 100) — the number of timer readings recorded by Pavel. Next lines represent n timer readings. Each reading is described with 3 lines 17 characters of length each, and encodes a timer value in MM:SS format (minutes and seconds).
Each timer digit is encoded in 9 characters: three characters in each of 3 strings. Higher order digit for minutes is encoded with characters in the positions 1−3 (here and further positions are enumerated starting with 1), lower order digit for minutes — with characters 5−7, higher order digit for seconds — with characters in the positions 11−13, lower order digit for seconds — with characters 15−17. Characters ’_’ (underscore, decimal ASCII code 95), ’|’ (vertical bar, decimal ASCII code 124) and ’.’ (full stop, decimal ASCII code 46) are used to encode digits. Code descriptions for all nine digits (with all segments displayed) are listed below.
._. ... ._. ._. ... ._. ._. ._. ._. ._.
|.| ..| ._| ._| |_| |_. |_. ..| |_| |_|
|_| ..| |_. ._| ..| ._| |_| ..| |_| ._|
Character ’*’ (asterisk, decimal ASCII code 42) stands in the ninth position at the timer’s readings lines 2 and 3,and all positions not mentioned above contain full stops.
If a segment of a digit is not displayed at the dial, this character will be replaced with a full stop in its encoded representation (segments encoded with full stop are always displayed correctly).

Output

Output n MM:SS formatted lines representing the recovered sequence of timer’s values. Line i must correspond with the i-th reading and has to be a valid time value between 00:00 and 59:59. Each subsequent value must be strictly less than the preceding one. If several answers exist, output any of them. It is guaranteed that there is at least one consistent sequence.

Example

inputoutput
2
._..._........._.
|...._|.*...|.._|
|_|.._..*...|.|..
....._....._..._.
|.|...|.*.|.|.._.
|.|.|_..*.|_|.._.
03:12
00:05

思路:按时间从大到小搜就好了,代码还是挺短的,不过还是感觉被恶心到了。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define MP make_pair
 6 #define PB push_back
 7 typedef long long LL;
 8 typedef pair<int,int> PII;
 9 const double eps=1e-8;
10 const double pi=acos(-1.0);
11 const int K=1e6+7;
12 const int mod=1e9+7;
13 
14 int ch[10];
15 char ss[500][100];
16 char num[5][100]=
17 {   " ",
18     " ._....._.._....._.._.._.._.._.",
19     " |.|..|._|._||_||_.|_...||_||_|",
20     " |_|..||_.._|..|._||_|..||_|._|"
21 };
22 bool sc(int sk,int x,int y)
23 {
24     for(int i=0;i<3;i++)
25         for(int j=0;j<3;j++)
26         {
27             if(!(ss[sk+i][x+j]=='.'||ss[sk+i][x+j]==num[i+1][y+j]))
28                 return 0;
29         }
30     return 1;
31 }
32 
33 int main(void)
34 {
35     for(int i=0;i<10;i++)
36         ch[i]=i*3+1;
37     int t,ln=0;cin>>t;
38     gets(ss[0]);
39     for(int i=1;i<=3*t;i++)
40         gets(&ss[i][1]);
41     for(int i=5;i>=0;i--)
42         for(int j=9;j>=0;j--)
43             for(int k=5;k>=0;k--)
44                 for(int p=9;p>=0;p--)
45                 if(sc(1+ln*3,1,ch[i])&&sc(1+ln*3,5,ch[j])&&sc(1+ln*3,11,ch[k])&&sc(1+ln*3,15,ch[p]))
46                 {
47                     printf("%d%d:%d%d
",i,j,k,p);
48                     if(++ln>=t)
49                         return 0;
50                 }
51     while(1);
52 }

 

原文地址:https://www.cnblogs.com/weeping/p/6375138.html