快6点才想起来今个有google的在线测试。。。。
那么老长的英文的题目我都能看懂,说明英语跟六级没有直接关系。。
尼玛为毛国企银行移动联通小灵通神马的还要六级!!!!!
六级求过
Problem A. Seven-segment Display
This contest is open for practice. You can try every problem as many times as you like, though we won‘t keep track of which problems you solve. Read the Quick-Start
Guideto get started.
Small input
8 points |
Download your output file: source file(s): not needed for the practice contest |
Large input
14 points |
Download your output file: source file(s): not needed for the practice contest |
Problem
Tom is a boy whose dream is to become a scientist, he invented a lot in his spare time. He came up with a great idea several days ago: to make a stopwatch by himself! So he bought a seven-segment display immediately.
The seven elements of the display are all light-emitting diodes (LEDs) and can be lit in different combinations to represent the arabic numerals like:
However, just when he finished the programs and tried to test the stopwatch, some of the LEDs turned out to be broken! Some of the segments can never be lit while others worked fine. So the display kept on producing some ambiguous states all the time...
Tom has recorded a continuous sequence of states which were produced by the display and is curious about whether it is possible to understand what this display was doing. He thinks the first step is to determine the state which the display will show next,
could you help him?
Please note that the display works well despite those broken segments, which means that the display will keep on counting down cyclically starting from a certain number (can be any one of 0-9 since we don‘t know where this record starts
from). ‘Cyclically‘ here means that each time when the display reaches 0, it will keep on counting down starting from 9 again.
For convenience, we refer the seven segments of the display by the letters A to G as the picture below:
For example, if the record of states is like:
It‘s not that hard to figure out that ONLY segment B is broken and the sequence of states the display is trying to produce is simply "9 -> 8 -> 7 -> 6 -> 5". Then the next number should be 4, but considering of the brokenness of segment B, the next state
should be:
Input
The first line of the input gives the number of test cases, T. Each test case is a line containing an integer N which is the number of states Tom recorded and a list of the Nstates separated by spaces. Each
state is encoded into a 7-character string represent the display of segment A-G, from the left to the right. Characters in the string can either be ‘1‘ or ‘0‘, denoting the corresponding segment is on or off, respectively.
Output
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1). If the input unambiguously determines the next state of the display, y should be that next state (in the same format as the input). Otherwise,
y should be "ERROR!".
Limits
1 ≤ T ≤ 2000.
Small dataset
1 ≤ N ≤ 5.
Large dataset
1 ≤ N ≤ 100.
Sample
Input |
|
4 1 1111111 2 0000000 0001010 3 0100000 0000111 0000011 5 1011011 1011111 1010000 1011111 1011011 |
|
|
|
Output | |
Case #1: 1110000 Case #2: ERROR! Case #3: 0100011 Case #4: 0010011 |
首先定义0-9的数组以及他们的7位代码,作为数字的参照
在验证过程中根据输入的几组数确定哪几个灯可能坏掉
比如拿第3组举例
0100000 0000111 0000011
(后边用a1 a2 a3 代替)
因为只有全是0的灯可能是坏掉的,所以将三个数字的代码做或操作 然后取反 得到结果 1011000(取名test) 表示1所在的灯可能是坏的,也就是说从给出的数字可以推断 a c d 位置的灯有可能是坏的
然后跑一个10次的循环:
a1 代码与9 的代码比较 如果 a1或9 = 9 并且 ((9异或a1)或 test = test 说明 a1可以为9
然后对a2 和 8 ,a3和7 重复上述操作
如果以上都成立 则推断下一个为6
如果有一个不成立则跳出循环对a1与下一个进行比较(也就是a1 8, a2 7, a3 6)
知道最后(a1 0,a2 9, a3 8)都没有找到成立的则ERROR!
大概就是这样吧。。。
差不多就是一个次数是10(因为有0-9十个数)的循环 套一个数字个数(n)的循环
时间复杂读是多少o(10n) 吗 还是 o(n)?
没写代码验证,不知道算法对不对,应该是对的吧。。。。
google 2015最新的校招测试题与思路