Problem B: Bulbs
Problem B: Bulbs
Greg has an m×n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. Initially, some of the bulbs are on and some are off. Greg can toggle some bulbs by shooting his laser at them. When he shoots his laser at a bulb, it toggles that bulb between on and off. But, it also toggles every bulb directly below it, and every bulb directly to the left of it. What is the smallest number of times that Greg needs to shoot his laser to turn all the bulbs on?
Input
The first line of input contains a single integer T (1 ≤ T ≤ 10), the number of test cases. Each test case starts with a line containing two space-separated integers m and n (1 ≤ m,n ≤ 400). The next m lines each consist of a string of length n of 1s and 0s. A 1 indicates a bulb which is on, and a 0 represents a bulb which is off.
Output
For each test case, output a single line containing the minimum number of times Greg has to shoot his laser to turn on all the bulbs.
Sample Input
2
3 4
0000
1110
1110
2 2
10
00
Sample Output
1
2
Explanation
In the first test case, shooting a laser at the top right bulb turns on all the bulbs which are off, and does not toggle any bulbs which are on.
In the second test case, shooting the top left and top right bulbs will do the job.
题意:把所有0,变成1最少需要几次;规则:如果把0变成1同时把左边的数和下边的数同时改变,
题解:从左上角开始处理,for循环遍历即可
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int n,m,ans=;
int a[],b[];
string s[];
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
ans=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=;i<n;i++)
cin>>s[i];
for(int i=;i<n;i++)
{
for(int j=m-;j>=;j--)
{
int x=s[i][j]-''+a[i]+b[j];
if(x%==)
{
ans++;
a[i]++;
b[j]++;
}
}
}
cout<<ans<<endl;
}
}
Problem B: Bulbs的更多相关文章
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- HDU 5601 N*M bulbs 找规律
N*M bulbs 题目连接: http://codeforces.com/contest/510/problem/C Description NM个灯泡排成一片,也就是排成一个NM的矩形,有些开着, ...
- BestCoder Round #67 (div.2) N bulbs(hdu 5600)
N bulbs Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- N bulbs(规律)
N bulbs Accepts: 408 Submissions: 1224 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 655 ...
- zoj 2976 Light Bulbs(暴力枚举)
Light Bulbs Time Limit: 2 Seconds Memory Limit: 65536 KB Wildleopard had fallen in love with hi ...
- 哈理工2015 暑假训练赛 zoj 2976 Light Bulbs
MS Memory Limit:65536KB 64bit IO Format:%lld & %llu SubmitStatusid=14946">Practice ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
随机推荐
- docker进入交互界面
进入cmd交互界面 docker run -it python:3.5 /bin/bash 退出 exit ctrl + d
- c++ 读取、保存单张图片
转载:https://www.jb51.net/article/147896.htm 实际上就是以二进制形式打开文件,将数据保存到内存,在以二进制形式输出到指定文件.因此对于有图片的文件,也可以用这种 ...
- 《容器化.NET应用架构指南》脑图学习笔记(第一部分)
一.关于这本官方“圣经” 作为.NET程序员,对于微软官方推动的架构示例总是特别关注,从PetShop到MusicStore再到eShopOnContainers,每一次关注,都会了解到业界最新的架构 ...
- 学习Java的书籍资料
对于程序员来说,编程技术至关重要,然而技术的提高不是一蹴而就的,它需要时间的积累和经验的沉淀.因此本文为大家推荐Java学习的书籍,学虽容易,学好不易,且学且珍惜. 基础类.<Java从入门到精 ...
- 对于JAVA语言的一点理解
java作为一门面向对象的语言,现在常常被用于企业服务器端的后台开发.同时,C语言可能更多地是用于嵌入式的开发,所谓的嵌入式就是航天飞机上的设备软件之类的东西.但是,我逐渐发现,我们平时所说的java ...
- kubernetes 使用flannel网络模式 错误分析
今天按照网上和书上的要求,将目前的kubernetes网络换成flannel.其实配置起来还是很简单的,但是一旦出现了问题,将很难解决. 配置方法我这边不给出了.因为网上这样的教程一大把,在说下去也无 ...
- mac允许安装任何来源的软件
如果在“系统偏好设置”--“安全性与隐私”--“通用”版面没有像下面的选项.那么请打开终端,使用命令行操作,之后重新进刚刚的设置界面,会出现“任何来源”的选项. 命令行:(请复制使用) sudo sp ...
- Xcode Edit Schemes
关于本文:有关“Xcode Edit Schemes”的设置,还是有很大的学问的.由于时间关系,我一点一点的补充. 1.在开发的时候,至少将Run的Build Configuration设置为Debu ...
- UIViewContentModel图解+文解
typedef NS_ENUM(NSInteger, UIViewContentMode) { //图片拉伸填充至整个UIImageView(图片可能会变形),这也是默认的属性,如果什么都不设置就是它 ...
- react 开发 vscode需要安装的开发插件
1.npm Intellisense 有自动补全的功能 var lodash = require('lodash') 2. path Intellisense 自动补全文件名 import C ...