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 ...
随机推荐
- 实用类-<Math类常用>
Math.random() //取0~1之间的随机数(不包括1) Math.max(数字1,数字2) //取两个数中最大的一个 Math.min(数字1,数字2) //取两个数中最小的一个 Math. ...
- Graphviz 使用笔记
官网:Graphviz 最近一直在找如何用写代码的方式就可以实现数据结构可视化.流程图等等,于是发现了她,上手也比较简单,但正当我仅觉得不错的时候,我发现竟然还可以用python来写,瞬间好感度爆满啊 ...
- 设计模式课程 设计模式精讲 8-2 单例设计模式-懒汉式及多线程Debug实战
1 主要内容 1.1 多线程debug 1.2 synchronized同步锁的调用 1.3 懒加载的应用 2 代码演练 2.1 单线程调用 2.2 多线程调用 2.3 锁的调用 1 主要内容 1.1 ...
- 如何使用ffmpeg进行音视频裁剪命令和音视频合成命令
音视频剪裁命令 ffmpeg -i input.mp4 -ss 00:00:00 -t 10 out.ts -i : 指定视频 -ss : 开始时间 -t : 指定裁剪的秒数 音视频合并的命令 ffm ...
- Flask - 总结
1. Flask.Django.Tornado框架区别 2. Flask快速入门 3. 配置文件 4. 路由系统 5. 模板 6. 请求&响应相关 7. session & cooki ...
- 键盘类型UIKeyboardType
UITextField.UITextView等能够调出系统键盘的控件,通过下面这个属性可以控制弹出键盘的样式: self.priceTextField.keyboardType = UIKeyboar ...
- 【快学springboot】13.操作redis之String数据结构
前言 在之前的文章中,讲解了使用redis解决集群环境session共享的问题[快学springboot]11.整合redis实现session共享,这里已经引入了redis相关的依赖,并且通过spr ...
- Wordpress综合检测和爆破工具
WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站. 也可以把 WordPress当作一个内容管理系统(CMS)来使用.WordP ...
- CNN反向传播算法过程
主模块 规格数据输入(加载,调格式,归一化) 定义网络结构 设置训练参数 调用初始化模块 调用训练模块 调用测试模块 画图 初始化模块 设置初始化参数(输入通道,输入尺寸) 遍历层(计算尺寸,输入输出 ...
- 【ABP】从零开始学习ABP_001_新建实体功能
上一篇文章中介绍了如何下载.运行ABP Zero示例项目,这个示例项目可以直接作为模板进行二次开发,很适合做企业开发框架. 本未介绍基于ABP Zero示例项目,如何新建一个自定义的实体. 此处已Eq ...