Bulbs【暴力?】

时间:2021-03-19 09:06:47

问题 B: Bulbs

时间限制: 1 Sec  内存限制: 128 MB

提交: 216  解决: 118

[提交] [状态] [命题人:admin]

题目描述

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?

输入

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.

输出

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.

样例输入

2
3 4
0000
1110
1110
2 2
10
00

样例输出

1
2

提示

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.

题意: 给你一个灯泡组成的图  1代表开 0代表关  每次操作可以切换一个灯的状态,会导致同行的左边所有灯泡和同列的下边所有灯泡状态都会改变 问把所有灯都打开(全1)最少需要几次操作

别问,问就是暴力。。从上到下,从右到左,如果遇到0就改变左边和下边的状态。

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef pair<int,int> P;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 405;
char b[maxn][maxn];
int a[maxn][maxn];
int n, m;
int ans ;
int main() {
    int t;
    read(t);
    while (t--) {
        read2(n,m);
        for (int i = 0; i < n; i++) {
            scanf("%s", b[i]);
            for (int j = 0; j < m; j++) {
                a[i][j] = b[i][j] - '0';
            }
        }
        ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] == 0) { //如果遇到0就改变左边和下边的状态
                    ans++;
                    for (int left = 0; left <= j - 1; left++) {
                        a[i][left] ^= 1;
                    }
                    for (int down = i + 1; down < n; down++) {
                        a[down][j] ^= 1;
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Bulbs【暴力?】的更多相关文章

  1. zoj 2976 Light Bulbs(暴力枚举)

    Light Bulbs Time Limit: 2 Seconds      Memory Limit: 65536 KB Wildleopard had fallen in love with hi ...

  2. upc组队赛5 Bulbs

    Bulbs 题目描述 Greg has an m × n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. Ini ...

  3. zone&period;js - 暴力之美

    在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...

  4. &lbrack;bzoj3123&rsqb;&lbrack;sdoi2013森林&rsqb; &lpar;树上主席树&plus;lca&plus;并查集启发式合并&plus;暴力重构森林&rpar;

    Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数 ...

  5. HDU 5944 Fxx and string(暴力&sol;枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  6. 1250 Super Fast Fourier Transform&lpar;湘潭邀请赛 暴力 思维&rpar;

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

  7. fragment&plus;viepager 的简单暴力的切换方式

    这里是自定义了一个方法来获取viewpager private static ViewPager viewPager; public static ViewPager getMyViewPager() ...

  8. ACM&colon; Gym 101047M Removing coins in Kem Kadr&&num;227&semi;n - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  9. uoj98未来程序改 纯暴力不要想了

    暴力模拟A了,数据还是良(shui)心(shui)的 90分的地方卡了半天最后发现一个局部变量被我手抖写到全局去了,,, 心碎*∞ 没什么好解释的,其实只要写完表达式求值(带函数和变量的),然后处理一 ...

随机推荐

  1. 机器学习理论知识部分--偏差方差平衡(bias-variance tradeoff)

    摘要: 1.常见问题 1.1 什么是偏差与方差? 1.2 为什么会产生过拟合,有哪些方法可以预防或克服过拟合? 2.模型选择例子 3.特征选择例子 4.特征工程与数据预处理例子 内容: 1.常见问题 ...

  2. CAS 集群部署session共享配置

    背景 前段时间,项目计划搞独立的登录鉴权中心,由于单独开发一套稳定的登录.鉴权代码,工作量大,最终的方案是对开源鉴权中心CAS(Central Authentication Service)作适配修改 ...

  3. 各种python环境的问题

    [OS] mac [ERROR] decoder jpeg not available [SOLUTION] $ pip uninstall pillow $ brew install libjpeg ...

  4. 修改sql2005字段

    alter table 表名 add 字段名 数据类型 default 默认值 增加:alter table AdCategory ADD SEOTitleNo varchar(50); 删除:ALT ...

  5. Linux&lpar;Debian&rpar;上安装Redis教程

    -- 第一步下载文件到该目录 cd /usr/local/src wget http:.tar.gz 解压 tar xzf redis.tar.gz -- 第二步编译安装 make make all ...

  6. 使用SVN clang&colon; error&colon; linker command failed with exit code 1 &lpar;use -v to see invocation&rpar;

    然后上传到该项目SVN仓库上,例如,下面的错误再次发生再拉到本地编译 ld: library not found for -lxxxxxxxxxxxx clang: error: linker com ...

  7. 《JavaScript设计模式与开发实践》读书笔记之单例模式

    1.单例模式 保证一个类仅有一个实例,并提供一个访问它的全局访问点 1.1 传统的单例模式 var Singleton=function(name){ this.name=name; } Single ...

  8. zip error&colon; Invalid command arguments

    在编译使用svn管理的android代码时,会出现如下错误: zip error: Invalid command arguments (cannot repeat names in zip file ...

  9. BZOJ1493 NOI2007 项链工厂 线段树模拟

    提交地址:http://www.lydsy.com/JudgeOnline/problem.php?id=1493 题目大意:给一个数列,进行一系列操作.包括旋转,翻转,改变等操作,以及查询颜色段数. ...

  10. Java学习笔记——判断字符Character类

    常用方法 下面所说的均是静态方法,也就是可以不创建对象直接调用 例:Character.isLetter(char c); isLetter 判断参数是否为字母(不分大小写),返回结果 isDigit ...