zoj3954 Seven-Segment Display
来源:互联网 发布:有了源码怎么做软件 编辑:程序博客网 时间:2024/06/06 18:05
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.
A seven segment code of permutation p is a set of seven segment code derived from the standard code by rearranging the bits into the order indicated by p. For example, the seven segment codes of permutation "gbedcfa" which is 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.
We indicate the seven segment code of permutation p representing number x as cp, x. For example cabcdefg,7 = 0001111, and cgbedcfa,7 = 1011010.
Given n seven segment codes s1, s2, ... , sn and the numbers x1, x2, ... , xn each 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 T test 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 n lines, the i-th line 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 for each test case.
Output
For each test case, output "YES" (without the quotes) if the permutation p exists. Otherwise output "NO" (without the quotes).
Sample Input
391 10011112 00100103 00001104 10011005 01001006 01000007 00011118 00000009 000010021 10011117 101001127 01010111 1101011
Sample Output
YESNOYES
Hint
For the first test case, it is a standard combination of the seven segment codes.
For the second test case, we can easily discover that the permutation p does not exist, as three in seven bits are different between the seven segment codes of 1 and 7.
For the third test case, p = agbfced.
思路:搜其他博客的题解吧
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int suma[10],sumb[10],a[10],b[10];int vis[10];int main(){ int t; scanf("%d",&t); while(t--) { b[1]=1001111; b[2]=10010; b[3]=110; b[4]=1001100; b[5]=100100; b[6]=100000; b[7]=1111; b[8]=0; b[9]=100; memset(a,0,sizeof(a)); memset(suma,0,sizeof(suma)); memset(sumb,0,sizeof(sumb)); memset(vis,0,sizeof(vis)); int n,x; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&x); scanf("%d",&a[x]); vis[x]=1; } for(int i=0; i<7; i++) for(int j=0; j<=9; j++) { if(vis[j]) { suma[i]=suma[i]*10+a[j]%10; sumb[i]=sumb[i]*10+b[j]%10; a[j]/=10; b[j]/=10; } } int ans=0; sort(suma,suma+7); sort(sumb,sumb+7); for(int i=0;i<10;i++) { if(suma[i]!=sumb[i]) ans=1; } if(ans) printf("NO\n"); else printf("YES\n"); }}
- zoj3954 Seven-Segment Display
- 【ZOJ3954 The 17th Zhejiang University Programming Contest G】【预处理 哈希 二分】Seven-Segment Display 矩阵列全排列的
- Seven-segment Display
- Seven-Segment Display
- ZOJ Seven Segment Display
- Seven-Segment Display
- Problem A. Seven-segment Display
- Google-APAC2015-"Seven-segment display"
- ZOJ 3954 Seven-Segment Display
- ZOJ 3954 Seven-Segment Display
- Seven Segment Display----数位dp
- ZOJ 3962 Seven Segment Display
- 【ZOJ 3962 Seven Segment Display】
- Seven Segment Display(数位dp)
- ZOJ 3954 Seven-Segment Display
- C#版Seven Segment LED(Display)
- ZOJ 3954 Seven-Segment Display(思维)
- ZOJ 3954 Seven-Segment Display (预处理)
- perl MQSeries::Queue sync方法
- Swoole 安装 使用
- Android 自定义编译时注解1
- 在 Linux 下学习 C 语言有什么好处?
- mysql数据库jdbc连接通用类
- zoj3954 Seven-Segment Display
- 概率图模型之:贝叶斯网络
- Isomorphic Strings
- Linux下jdk的安装
- 2D sprite outlines
- UE4场景中电视机播放视频,并产生辉光效果
- 深入理解Android的startservice和bindservice
- 漫步数理统计二十——多元随机变量
- MyBatis报错: Parameter '*' not found. Available parameters are [1, 0, param1, param2]