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 = offA 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?
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.
For each test case, output "YES" (without the quotes) if the permutation p exists. Otherwiseoutput "NO" (without the quotes).
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.
#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; }