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 froma
tog, 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
1 1 0 0 1 1 1 1
2 0 0 1 0 0 1 0
3 0 0 0 0 1 1 0
4 1 0 0 1 1 0 0
5 0 1 0 0 1 0 0
6 0 1 0 0 0 0 0
7 0 0 0 1 1 1 1
8 0 0 0 0 0 0 0
9 0 0 0 0 1 0 0
0 = on 1 = off

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.

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

We indicate the seven segment code of permutationp representing numberx
ascp,x. For
examplecabcdefg,7 = 0001111, andcgbedcfa,7
= 1011010.

Given n seven segment codess1,s2,
... ,sn and the numbersx1,x2,
... ,xn each of them represents, can you find a permutationp,
so that for all 1 ≤in,si
=cp,xi
holds?

Input

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

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

For the next n lines, thei-th line contains a numberxi
(1 ≤xi ≤ 9) and a seven segment codesi
(|si| = 7), their meanings are described above.

It is guaranteed that ∀ 1 ≤ i <jn,xi
xj holds for each test case.

Output

For each test case, output "YES" (without the quotes) if the permutationp exists. Otherwise output "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
   思路如下:
   1:大数据?????一脸懵逼,以每个permutation排序为状态加以判断?不行!
   2:大数据?????估计一下,搜索加剪枝?不行!
   3:大数据,骂题主,准备放弃?不行!
   4:算了,看看样例,发现与未出现的行无关。
   5:可能会想到以y轴方向判断来解决问题。好像可以珜。
  引申:如何判断两个字符串的单个字母的集合(可重复)相同。如s1=“abacc”
s2=“aabcc”。absolutely,用排序:sort(s,s+L)。然后用函数比较,或者单个顺序比较单个字母。
   6,此题就是问已知函数和目标函数是否可以经过排序得到。
   7,x方向排序,以y方向为单位,从上向下连接成字符串或者数字,如y轴=a时,x[1]=1,x[2]=0,x[3]=1.....x[9]=1;
得到字符串或数“101....1”。遇到的题目往往数字过大,而且因为每一位只用了0或1而造成浪费,所以用看成二进制的0或1,此题由于数不大,没有必要,直接上十进制。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<memory.h>
#include<cstring>
#include<algorithm>
using namespace std;
int m[10][8]={0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0};//我自己手动打表,mmp
int num[10];//为了越界最好可以开大一点,不过我为了刷排名,开到了最小
int ans[8];
int st[8];
void _in()
{
int s,i,j;
char c[10][8];
scanf("%d",&s);//换成cin就不能AC ,可以试一试
for(i=1;i<=s;i++){
scanf("%d",&num[i]);
for(j=0;j<=7;j++) c[i][j]=getchar();//j=0时是输入的空格
//如果是cin则不必考虑空格
        }
for(i=1;i<=7;i++)
{
ans[i]=0;
for(j=1;j<=s;j++)
ans[i]=ans[i]*10+c[j][i]-'0';//c[]保持的字符,需要///减去‘0’或者48
}
for(i=1;i<=7;i++)
{
st[i]=0;
for(j=1;j<=s;j++)
st[i]=st[i]*10+m[num[j]][i];
}
sort(ans+1,ans+8);//排序再比较
sort(st+1,st+8);
bool temp=true;//也可以用函数直接比较st和ans是否相同,本题小,懒得搞
for(i=1;i<=7;i++) if(ans[i]!=st[i]) temp=false;
if(temp) printf("YES\n");
else printf("NO\n");
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--) _in();
return 0;
} //
2017-08-08 14:17:54 C++ 120ms 284kb fcy6  时间上已经很优了

												

zoj3954 详细讲解 排序比较单词法的更多相关文章

  1. vue-cli 目录结构详细讲解

    https://juejin.im/post/5c3599386fb9a049db7351a8 vue-cli 目录结构详细讲解 目录 结构预览 ├─build // 保存一些webpack的初始化配 ...

  2. 第五节:详细讲解Java中的接口与继承

    前言 大家好,给大家带来详细讲解Java中的接口与继承的概述,希望你们喜欢 什么是接口(interface) 接口中的方法都是抽象方法,public权限,全是抽象函数,不能生成对象 interface ...

  3. 第四节:详细讲解Java中的类和面向对象思想

    前言 大家好,给大家带来详细讲解Java中的类和面向对象思想的概述,希望你们喜欢 类和面向对象 在Java中怎样理解对象,创建对象和引用:什么是引用,对于基础学习的同学,要深入了解引用.示例:Stri ...

  4. 第二十三节:Java语言基础-详细讲解函数与数组

    函数 函数在Java中称为方法,在其他语言中可能称为函数,函数,方法就是定义在类中具有特定功能的程序.函数,在Java中可称为方法. 函数的格式: 修饰符 返回值类型 函数名(参数类型 参数1, 参数 ...

  5. 第十节:详细讲解一下Java多线程,随机文件

    前言 大家好,给大家带来第十节:详细讲解一下Java多线程,随机文件的概述,希望你们喜欢 多线程的概念 线程的生命周期 多线程程序的设计 多线程的概念 多线程的概念:程序是静态的,进程是动态的.多进程 ...

  6. 万字长文,以代码的思想去详细讲解yolov3算法的实现原理和训练过程,Visdrone数据集实战训练

    以代码的思想去详细讲解yolov3算法的实现原理和训练过程,并教使用visdrone2019数据集和自己制作数据集两种方式去训练自己的pytorch搭建的yolov3模型,吐血整理万字长文,纯属干货 ...

  7. 30 道 Vue 面试题,内含详细讲解(涵盖入门到精通,自测 Vue 掌握程度)

    前言 本文以前端面试官的角度出发,对 Vue 框架中一些重要的特性.框架的原理以问题的形式进行整理汇总,意在帮助作者及读者自测下 Vue 掌握的程度.本文章节结构以从易到难进行组织,建议读者按章节顺序 ...

  8. head标签详细讲解

    head标签详细讲解 head位于html网页的头部,后前的标签,并以开始以结束的一html标签. Head标签位置如图: head标签示意图 head包含标签 meta,title,link,bas ...

  9. Hadoop阅读笔记(三)——深入MapReduce排序和单表连接

    继上篇了解了使用MapReduce计算平均数以及去重后,我们再来一探MapReduce在排序以及单表关联上的处理方法.在MapReduce系列的第一篇就有说过,MapReduce不仅是一种分布式的计算 ...

随机推荐

  1. Android学习记录:获取联系人

    在AndroidManifest中申请读取联系人的权限 <uses-permission android:name = "android.permission.READ_CONTACT ...

  2. 垂直居中小记 line-height table vertical-align:middle

    垂直居中分两种情况:1.父元素高度确定的单行文本        2.以及父元素高度确定的多行文本. 1.垂直居中-父元素高度确定的单行文本的竖直居中的方法是通过设置父元素的 height 和 line ...

  3. 控制结构(9) 管道(pipeline)

    // 上一篇:线性化(linearization) // 下一篇:指令序列(opcode) 最近阅读了酷壳上的一篇深度好文:LINUX PID 1 和 SYSTEMD.这篇文章介绍了systemd干掉 ...

  4. 201521123090《Java程序设计》第6周学习总结

    本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖面向对 ...

  5. 201521123007《Java程序设计》第3周学习总结

    1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 2. 书面作 ...

  6. 201521123034《java程序设计》第2周学习总结

    1. 本章学习总结 - String对象创建之后不能再进行修改,修改字符串使用Stringbuilder: - 检测字符串内容是否相同不用==,用equals的方法检测: - 使用一维数组的两个步骤: ...

  7. java课设 五子棋代码编写(团队)

    1. 团队课程设计博客链接 http://www.cnblogs.com/yzb123/p/7063424.html 2.个人责模块或任务说明 1.主函数编写,设置图形界面 2,设置功能按钮 3.使用 ...

  8. 201521123079《java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己 ...

  9. 201521123085 《java程序设计》 第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前 ...

  10. Markdown例

    一个例子: 例子开始 1. 本章学习总结 今天主要学习了三个知识点 封装 继承 多态 2. 书面作业 Q1. java HelloWorld命令中,HelloWorld这个参数是什么含义? 今天学了一 ...