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 <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = *1e3 + ;
const int mod = 1e9 + ;
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, , sizeof(sum) );
for( ll i = ; i < n; i ++ ) {
for( ll j = ; j < m; j ++ ) {
cin >> mapn[i][j];
sum[j] += mapn[i][j] - '';
}
}
bool flg = false;
for( ll i = ; i < n; i ++ ) {
bool flag = true;
for( ll j = ; j < m; j ++ ) {
if( sum[j] - ( mapn[i][j] - '' ) == ) {
flag = false;
break;
}
}
if( flag ) {
cout << "YES" << endl;
flg = true;
break;
}
}
if( !flg ) {
cout << "NO" << endl;
}
}
return ;
}

CF985B Switches and Lamps 思维 第十九的更多相关文章

  1. CF985B Switches and Lamps【矩阵操作/枚举】

    [链接]CF985B [题意]:给n盏灯,m个开关,每次按开关只能将灯从灯灭的状态转变为灯亮,问是否存在不按所有开关就将所有灯打开的方法. [分析]:有两种办法,一种代码复杂点,容易想到枚举去掉每一行 ...

  2. codeforce 985B Switches and Lamps(暴力+思维)

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

  3. 解释器模式 Interpreter 行为型 设计模式(十九)

      解释器模式(Interpreter)   考虑上图中计算器的例子 设计可以用于计算加减运算(简单起见,省略乘除),你会怎么做?    你可能会定义一个工具类,工具类中有N多静态方法 比如定义了两个 ...

  4. 无废话ExtJs 入门教程十九[API的使用]

    无废话ExtJs 入门教程十九[API的使用] extjs技术交流,欢迎加群(201926085) 首先解释什么是 API 来自百度百科的官方解释:API(Application Programmin ...

  5. Python之路【第十九章】:Django进阶

    Django路由规则 1.基于正则的URL 在templates目录下创建index.html.detail.html文件 <!DOCTYPE html> <html lang=&q ...

  6. Bootstrap <基础二十九>面板(Panels)

    Bootstrap 面板(Panels).面板组件用于把 DOM 组件插入到一个盒子中.创建一个基本的面板,只需要向 <div> 元素添加 class .panel 和 class .pa ...

  7. Bootstrap <基础十九>分页

    Bootstrap 支持的分页特性.分页(Pagination),是一种无序列表,Bootstrap 像处理其他界面元素一样处理分页. 分页(Pagination) 下表列出了 Bootstrap 提 ...

  8. Web 开发人员和设计师必读文章推荐【系列二十九】

    <Web 前端开发精华文章推荐>2014年第8期(总第29期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各类能够提升网站用户体验的优秀 jQuery 插件,展示前沿的 HTML5 ...

  9. Web 前端开发精华文章集锦(jQuery、HTML5、CSS3)【系列十九】

    <Web 前端开发精华文章推荐>2013年第七期(总第十九期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和 C ...

随机推荐

  1. ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core

    前言 原本本节内容是不存在的,出于有几个人问到了我:我想使用ASP.NET Core Identity,但是我又不想使用默认生成的数据库表,想自定义一套,我想要使用ASP.NE Core Identi ...

  2. 基于 Autojs 的 APP、小程序自动化测试 SDK - 2019年8月3日

    原文:https://blog.csdn.net/laobingm/article/details/98317394 autojs sdk基于 Autojs 的 APP.小程序自动化测试 SDK,支持 ...

  3. vagrant 创建虚拟机时遇到问题

    问题1 :  ceph-node3: Warning: Authentication failure. Retrying.. 问题分析: ssh 认证失败,在向虚拟机拷贝内容时权限不足. 解决办法: ...

  4. 一份新的lilypond谱子,能设置页边距和设置换页符了

    给学生做的一份乐谱,这回能设置页边距了,以及设置换页符了. 顺带能设置一些代码片段(snippet),可以用热键代替使用 设置页边距的snippet: \paper { %双引号里面填页面大小 #(s ...

  5. 佳木斯集训Day5

    今天是ACM赛制...本来可以400的,结果毒瘤T2模拟硬生生卡掉了我90分 T1是个大水题,找规律,5分钟AC没啥压力 #include <bits/stdc++.h> #define ...

  6. 干货 |《从Lucene到Elasticsearch全文检索实战》拆解实践

    1.题记 2018年3月初,萌生了一个想法:对Elasticsearch相关的技术书籍做拆解阅读,该想法源自非计算机领域红火已久的[樊登读书会].得到的每天听本书.XX拆书帮等. 目前市面上Elast ...

  7. zuul 路由网关 微服务架构系统中

    在微服务架构中,基本包含以下常见的组件.服务注册与发现.服务消费.负载均衡.断路器.只能路由.配置管理等.一个简单的微服务架构系统如下 一.Zuul简介 Zuul的主要功能是路由转发和过滤器.路由功能 ...

  8. 偏差和方差以及偏差方差权衡(Bias Variance Trade off)

    当我们在机器学习领域进行模型训练时,出现的误差是如何分类的? 我们首先来看一下,什么叫偏差(Bias),什么叫方差(Variance): 这是一张常见的靶心图 可以看左下角的这一张图,如果我们的目标是 ...

  9. node爬虫的几种简易实现方式

    说到爬虫大家可能会觉得很NB的东西,可以爬小电影,羞羞图,没错就是这样的.在node爬虫方面,我也是个新人,这篇文章主要是给大家分享几种实现node 爬虫的方式.第一种方式,采用node,js中的 s ...

  10. net必问的面试题系列之基本概念和语法

    上个月离职了,这几天整理了一些常见的面试题,整理成一个系列给大家分享一下,机会是给有准备的人,面试造火箭,工作拧螺丝,不慌,共勉. 1.net必问的面试题系列之基本概念和语法 2.net必问的面试题系 ...