博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF985B Switches and Lamps 思维 第十九
阅读量:5788 次
发布时间:2019-06-18

本文共 2821 字,大约阅读时间需要 9 分钟。

Switches and Lamps
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix aconsisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.

Initially all m lamps are turned off.

Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards.

It is guaranteed that if you push all n switches then all m lamps will be turned on.

Your think that you have too many switches and you would like to ignore one of them.

Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.

The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.

It is guaranteed that if you press all n switches all m lamps will be turned on.

Output

Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.

Examples
input
Copy
4 5 10101 01000 00111 10000
output
Copy
YES
input
Copy
4 5 10100 01000 00110 00101
output
Copy
NO 题意: 给你n*m盏灯,i行j列1代表i可以控制灯j的开关,0代表不可以,问是否可以去掉一行剩余的灯还是可以亮着。如果可以输出YES,不可以输出NO 遍历每一行,如果去掉哪行时剩余的每列有一列和不为0,那么证明可以去掉该行,输出YES
#include #include 
#include
#include
#include
#include
#include
#include
#include
#include
#define debug(a) cout << #a << " " << a << endlusing namespace std;const int maxn = 2*1e3 + 10;const int mod = 1e9 + 7;typedef long long ll;char mapn[maxn][maxn];ll sum[maxn];int main(){ std::ios::sync_with_stdio(false); ll n, m; while( cin >> n >> m ) { memset( sum, 0, sizeof(sum) ); for( ll i = 0; i < n; i ++ ) { for( ll j = 0; j < m; j ++ ) { cin >> mapn[i][j]; sum[j] += mapn[i][j] - '0'; } } bool flg = false; for( ll i = 0; i < n; i ++ ) { bool flag = true; for( ll j = 0; j < m; j ++ ) { if( sum[j] - ( mapn[i][j] - '0' ) == 0 ) { flag = false; break; } } if( flag ) { cout << "YES" << endl; flg = true; break; } } if( !flg ) { cout << "NO" << endl; } } return 0;}

 

转载于:https://www.cnblogs.com/l609929321/p/9234067.html

你可能感兴趣的文章
C#_细说Cookie_Json Helper_Cookies封装
查看>>
对事件循环的一点理解
查看>>
在mui中创建aJax来请求数据..并展示在页面上
查看>>
spring 之AOP
查看>>
总结 15/4/23
查看>>
守护进程
查看>>
前端BOM和DOM
查看>>
安装linux环境及相关包方法
查看>>
C++ 键盘钩子
查看>>
Python 导入requests报错No module named requests
查看>>
1106冒泡排序语法树
查看>>
堆排序实现(C++)
查看>>
Java Programming Test Question 2
查看>>
3V、5V混合系统中不同电平器件接口的4种情况
查看>>
服务调用效率比较
查看>>
hhgis驱动
查看>>
UML类图几种关系的总结
查看>>
Struts2——解耦方式
查看>>
jmeter使用中的问题
查看>>
关于HTML+CSS3的一些笔记
查看>>