ZOJ 3954 Seven-Segment Display

xiaoxiao2021-02-28  117

InputOutputSample InputSample OutputHint Seven-Segment Display
Time Limit: 1 Second       Memory Limit: 65536 KB

      A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven segment displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information.

      The segments of a seven segment display are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top, middle, and bottom. If we refer the segments as the letters from a to g, it's possible to use the status of the segments which is called a seven segment code to represent a number. A standard combination of the seven segment codes is shown below.

X a b c d e f g 11001111 20010010 30000110 41001100 50100100 60100000 70001111 80000000 90000100     0 = on   1 = off

     A  seven segment code of permutation pis a set of seven segment code derived from the standard code by rearrangingthe bits into the order indicated by p.For example, the seven segment codes of permutation "gbedcfa" whichis derived from the standard code by exchanging the bits represented by"a" and "g", and by exchanging the bits represented by"c" and "e", is listed as follows.

X

g

b

e

d

c

f

a

1

1

0

1

1

0

1

1

2

0

0

0

0

1

1

0

3

0

0

1

0

0

1

0

4

0

0

1

1

0

0

1

5

0

1

1

0

0

0

0

6

0

1

0

0

0

0

0

7

1

0

1

1

0

1

0

8

0

0

0

0

0

0

0

9

0

0

1

0

0

0

0

Weindicate the seven segment code of permutation p representing number x as cp, x. For example cabcdefg,7 =0001111, and cgbedcfa,7= 1011010.

Givenn sevensegment codes s1,s2,... , snand the numbers x1,x2,... , xneach of them represents, can you find a permutation p, so that for all 1 ≤ i ≤ n, si = cp, xi holds?

Input

The first line of the input is an integer T(1 ≤ T ≤ 105),indicating the number of test cases. Then Ttest cases follow.

The first line of each test case contains an integer n (1 ≤ n≤ 9), indicating the number of seven segment codes.

For the next nlines, the i-thline contains a number xi(1 ≤ xi≤ 9) and a seven segment code si(|si|= 7), their meanings are described above.

It is guaranteed that ∀ 1 ≤ i < j ≤ n, xi ≠ xj holds foreach test case.

Output

For each test case, output "YES" (without the quotes) if the permutation p exists. Otherwiseoutput "NO" (without the quotes).

Sample Input

3 9 1 1001111 2 0010010 3 0000110 4 1001100 5 0100100 6 0100000 7 0001111 8 0000000 9 0000100 2 1 1001111 7 1010011 2 7 0101011 1 1101011

Sample Output

YES NO YES

Hint

Forthe first test case, it is a standard combination of the seven segment codes.

Forthe second test case, we can easily discover that the permutation p does not exist, asthree in seven bits are different between the seven segment codes of 1 and 7.

Forthe third test case, p= agbfced.

题意:给定1-9的标准序列号,一组样例中有n行,每行两个数,一个代表数,一个代表这个数的序列号,问这组样例中的序列号能否通过交换标准序列号中的若干列得到

思路:不论怎样变换,每一列的数字顺序是不会变的,只需要按列保存一下数,然后判断标准序列和给出序列的列是否两两对应即可

#include <bits/stdc++.h> using namespace std; #define mst(a,b) memset((a),(b),sizeof(a)) #define f(i,a,b) for(int i=(a);i<=(b);++i) #define ll long long const int maxn = 1e6+5; const ll mod = 1e9+7; const ll INF = (ll)0xffffffff+1; const double eps = 1e-6; #define rush() int T;scanf("%d",&T);while(T--) int a[10],suma[10],sumb[10]; bool vis[10]; void init() { mst(a,0); mst(suma,0); mst(sumb,0); mst(vis,0); } int main() { int n,x; rush() { init(); int b[10]={0,1001111,10010,110,1001100,100100,100000,1111,0,100}; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&x); scanf("%d",&a[x]); vis[x]=true; } for(int i=0;i<7;i++) for(int j=1;j<=9;j++) { if(vis[j]) { suma[i]=suma[i]*10+a[j]; sumb[i]=sumb[i]*10+b[j]; a[j]/=10; b[j]/=10; } } sort(suma,suma+7); sort(sumb,sumb+7); bool flag=false; for(int i=1;i<10;i++) { if(suma[i]!=sumb[i]) { flag=true; break; } } if(flag) printf("NO\n"); else printf("YES\n"); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-44696.html

最新回复(0)