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?

输入

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;
}

转载于:https://www.cnblogs.com/llke/p/10800031.html

upc组队赛5 Bulbs相关推荐

  1. upc组队赛1 小C的数学问题【单调栈】(POJ2796)

    小C的数学问题 题目描述 小C是个云南中医学院的大一新生,在某个星期二,他的高数老师扔给了他一个问题. 让他在1天的时间内给出答案. 但是小C不会这问题,现在他来请教你. 请你帮他解决这个问题. 有n ...

  2. upc 组队赛18 STRENGTH【贪心模拟】

    STRENGTH 题目链接 题目描述 Strength gives you the confidence within yourself to overcome any fears, challeng ...

  3. upc组队赛15 Supreme Number【打表】

    Supreme Number 题目链接 题目描述 A prime number (or a prime) is a natural number greater than 1 that cannot ...

  4. upc组队赛5 Election of Evil【搜索】

    Election of Evil 题目描述 Dylan is a corrupt politician trying to steal an election. He has already used ...

  5. upc组队赛16 GCDLCM 【Pollard_Rho大数质因数分解】

    GCDLCM 题目链接 题目描述 In FZU ACM team, BroterJ and Silchen are good friends, and they often play some int ...

  6. upc组队赛1 黑暗意志【stl-map】

    黑暗意志 题目描述 在数千年前潘达利亚从卡利姆多分离之时,迷雾笼罩着这块新形成的大陆,使它不被外来者发现.迷雾同样遮蔽着这片大陆古老邪恶的要塞--雷神的雷电王座.在雷神统治时期,他的要塞就是雷电之王力 ...

  7. upc组队赛1 不存在的泳池【GCD】

    不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...

  8. vscode不会自动生成html,vscode 快速生成html

    CoolTrayIcon4.0 CoolTrayIcon:在任务栏放置图标的控件,是同类空间中功能最为完善和强大的. 1.支持动态图标 2.交互式气球样式的提示框 3.支持bitmaps到icons的 ...

  9. UPC个人训练赛第十五场(AtCoder Grand Contest 031)

    传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...

最新文章

  1. 趣谈iOS运行时的方法调用原理
  2. CacheHelper
  3. POJ 1716 区间最小点个数
  4. sql 函数 汉字转拼音
  5. Spring Boot解决跨域问题
  6. 切换 uniapp_万能前端框架uni app初探03:底部导航开发
  7. sql 循环处理数据_图文介绍 SQL 的三种查询计划处理模型,Spark 用了其中两个
  8. 分布式任务队列--Celery的学习笔记
  9. [leetcode]LRU Cache
  10. Android开发笔记(八十九)单例模式
  11. JZ32 从上往下打印二叉树
  12. AIX下使用xmanager
  13. 第16课 火眼金睛——人脸识别
  14. excel 数组函数入门讲座
  15. 个人微信开发api文档
  16. 云开发【云函数的使用】
  17. 唐家三少的新作品《天珠变》的最近评论...
  18. php ppt如何转换成pdf,PHP将Word,Wps,Excel,PPT转成PDF
  19. 随机森林-sklearn.ensemble.RandomForestRegressor
  20. php输出setcookie,PHP函数:setcookie()

热门文章

  1. 如何在ashx页面获取Session值
  2. Windows 窗设计时结构
  3. MYSQL数据库VALUES_MySQL数据库“十宗罪”(十大经典错误案例)
  4. Graphpad Prism 9绘制子列图与柱状图
  5. OpenCV | 基于visual studio 2010版本的OpenCV3.0.0配置文件
  6. collect2: error: ld returned 1 exit status编译错误
  7. sublime配置python3环境_【env】Sublime配置Python3开发环境
  8. 优秀的程序员都有哪些习惯?
  9. 技术人的未来在哪里?
  10. 易企秀如何生成图片_易企秀可以导出图片吗