百练 / 2018大数据研究中心夏令营上机考试 E: What time is it?

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

E: What time is it?

总时间限制1000ms   内存限制65536kB

描述

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 is15 minutes late. For example, at 8:25am, the first accutron shows '0825', whilethe second shows '0810'.

Unfortunately, there is something wrong with the two LCD screens, namely someparts of the digits missed. Your task is to decide the accurate time, accordingto the fragmental digits showed on the two accutrons.

输入

The first line of the input is a single integer t (1 <= t<= 20), the number of test cases. Each case contains three lines, indicatingthe time on the accurate accutron and the time on the slow accutron, separatedby a blank column. (Please refer to the Sample Input.)

输出

For each input, print the accurate time with four digits if itcan be ensured, or otherwise the string 'Not Sure'.

样例输入

2
    _  _  _      _     _ 
  | _  _||       _   || 

  | _ |_   |   | _    |_|
    _  _  _   _  _     _ 
  ||_  _||       _|  ||  
  | _ |_   |   ||     |_|

样例输出

Not Sure
0825

来源

POJ Monthly--2004.06.27 鄂继明

--------------------------------------------------------------

思路

神级模拟题。思路很清晰,但代码量很大,测试数据很难写。

根据将火柴棒表达式按照7段数码管的二进制编码成整数,再枚举可能的完整字符,最后8重循环暴力判断。

两个注意点:

1. 00:00 – 23:45 = 25 min

2. gets(char*)一次读入一行字符串时,如果之前用了scanf,要清缓冲区,试了下fflush(stdin)不行,不知道为什么,只能在gets之前的那个scanf后面再加一个gets把那一行的空字符串读进来免得影响后面的gets

3. 高版本的VS里用freopen, scanf会报错,只能用freopen_s, scanf_s,在源文件最前面加

#define _CRT_SECURE_NO_WARNINGS

可以解决该错误(对,“_CRT_SECURE_NO_WARNINGS”就是错误提醒里的那串)

注意是“最前面”,要在#include那一串之前

4. 注意输入重定向freopen("文件名","r",stdin)的应用

5. 注意goto的应用(虽然貌似老师都很反对用goto)

-----------------------------------------------------

代码 

#include
#include
#include
using namespace std;

int a[8] = {};
int b[8] = {};
vector v[8];
const int DIGIT[10] = {(1<<7)-1-(1<<2), (1<<3)+(1<<6), 1+(1<<3)+(1<<2)+(1<<4)+(1<<5), 1+(1<<3)+(1<<2)+(1<<6)+(1<<5),
	(1<<1)+(1<<2)+(1<<3)+(1<<6), 1+(1<<1)+(1<<2)+(1<<6)+(1<<5), 1+(1<<1)+(1<<2)+(1<<4)+(1<<5)+(1<<6),
	1+(1<<3)+(1<<6), (1<<7)-1, (1<<7)-1-(1<<4)};
const int L[8] = {0,3,6,9,13,16,19,22};
const int M[8] = {1,4,7,10,14,17,20,23};
const int R[8] = {2,5,8,11,15,18,21,24};

int main()
{
#ifndef ONLINE_JUDGE
	freopen("E.txt","r",stdin);
#endif
	char l1[30],l2[30],l3[30];
	int t,i,j,k,i0,i1,i2,i3,i4,i5,i6,i7,h0,h1,m0,m1,cnt=0;
	int ans[4] = {};
	char ch;
	bool is_frag = true, has_cout = false;
	scanf("%d",&t); gets(l1);					// 加一个gets把t这行的空字符串读进去
	while (t--)
	{
		memset(a,0,sizeof(a));
		for (i=0; i<8; i++)
		{
			v[i].clear();
		}
		/* 输入字符以七段码二进制转化为整数 */
		gets(l1);
		for (i=0; i<8; i++)
		{
			if (l1[M[i]] == '_')
			{
				a[i] += (1<<0);
			}
		}
		gets(l2);
		for (i=0; i<8; i++)
		{
			if (l2[L[i]] == '|')
			{
				a[i] += (1<<1);
			}
			if (l2[M[i]] == '_')
			{
				a[i] += (1<<2);
			}
			if (l2[R[i]] == '|')
			{
				a[i] += (1<<3);
			}
		}
		gets(l3);
		for (i=0; i<8; i++)
		{
			if (l3[L[i]] == '|')
			{
				a[i] += (1<<4);
			}
			if (l3[M[i]] == '_')
			{
				a[i] += (1<<5);
			}
			if (l3[R[i]] == '|')
			{
				a[i] += (1<<6);
			}
		}
		/* 枚举可能的数字 */
		for (i=0; i<8; i++)
		{
			for (j=0; j<=9; j++)
			{
				is_frag = true;
				for (k=0; k<7; k++)
				{
					if ((a[i] & (1<=0 && h0<=23 && h1>=0 && h1<=23 && m0>=0 && m0<=59 && m1>=0 && m1<=59)
											{
												if ((h0==h1 && m0-m1==15) || (h0==h1+1 && m0+60-m1==15) || (h0==0 && h1==23 && m0+60-m1==15))
												{
													if (cnt==1)
													{
														cnt = 2;
														goto mark;
													}
													cnt = 1;
													ans[0] = b[0];
													ans[1] = b[1];
													ans[2] = b[2];
													ans[3] = b[3];
												}
											}
										}

									}

								}

							}

						}

					}

				}

			}
mark:;
			if (cnt==1)
			{
				printf("%d%d%d%d\n",ans[0],ans[1],ans[2],ans[3]);
			}
			else
			{
				printf("Not Sure\n");
			}
		}
	}
	return 0;
}


你可能感兴趣的:(百练OJ/poj)