sdut oj 2372 Annoying painting tool (【暴力枚举测试】1Y )
Annoying painting tool
题目描述
Maybe you wonder what an annoying painting tool is? First of all, the painting tool we speak of supports only black and white. Therefore, a picture consists of a rectangular area of pixels, which are either black or white. Second, there is only one operation how to change the colour of pixels:
Select a rectangular area of r rows and c columns of pixels, which is completely inside the picture. As a result of the operation, each pixel inside the selected rectangle changes its colour (from black to white, or from white to black).
Initially, all pixels are white. To create a picture, the operation described above can be applied several times. Can you paint a certain picture which you have in mind?
输入
The input contains several test cases. Each test case starts with one line containing four integers n, m, r and c. (1 ≤ r ≤ n ≤ 100, 1 ≤ c ≤ m ≤ 100), The following nlines each describe one row of pixels of the painting you want to create. The ith line consists of m characters describing the desired pixel values of the ith row in the finished painting (\'0\' indicates white, \'1\' indicates black).
The last test case is followed by a line containing four zeros.
输出
For each test case, print the minimum number of operations needed to create the painting, or -1 if it is impossible.
示例输入
3 3 1 1
010
101
010
4 3 2 1
011
110
011
110
3 4 2 2
0110
0111
0000
0 0 0 0
示例输出
4
6
-1
代码:
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h> using namespace std; int map[110][110];
int n, m, r, c;
bool judge(int dd, int ff)
{
if((dd+r-1)<=n && (ff+c-1)<=m )
return true;
else
return false;
} void OP(int dd, int ff)
{
int i, j;
for(i=dd; i<=(dd+r-1); i++)
{
for(j=ff; j<=(ff+c-1); j++)
{
if(map[i][j]==1)
map[i][j]=0;
else
map[i][j]=1;
}
}
} int main()
{
int flag;
int i, j, k, e;
char s[110];
int cnt;
while(scanf("%d %d %d %d", &n, &m, &r, &c)!=EOF)
{
if(n==0&&m==0&&r==0&&c==0 )
break;
flag=1;
cnt=0;
for(i=1; i<=n; i++)
{
scanf("%s", s);
int len=strlen(s);
for(j=0; j<len; j++)
map[i][j+1]=s[j]-48;
}
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
if(map[i][j]==1)
{
if(judge(i, j)==true)
{
OP(i, j); cnt++;
}
else
{
flag=0; break;
}
}
}
if(flag==0) break;
}
if(flag==0)
printf("-1\n");
else
printf("%d\n", cnt );
}
return 0;
}
sdut oj 2372 Annoying painting tool (【暴力枚举测试】1Y )的更多相关文章
- BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定
题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...
- [Swust OJ 763]--校门外的树 Plus(暴力枚举)
题目链接:http://acm.swust.edu.cn/problem/0763/ Time limit(ms): 1000 Memory limit(kb): 65535 西南某科技大学的校门外有 ...
- SDUT OJ 1221 亲和数 (找出某个数n所有的因子数,只需要暴力:2->sqrt(n) 即可 )
亲和数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 如果a的因子和等于b,b的因子和等于a,且a≠b,则称a,b为亲和数对. ...
- SDUT OJ 2607
/*http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607*/ 题目大意:给出一个字符串,求出里 ...
- HDU 1015.Safecracker【暴力枚举】【8月17】
Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is lo ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
/* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
- 51nod 1116 K进制下的大数 (暴力枚举)
题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...
随机推荐
- Leetcode 数组问题3:旋转数组
问题描述: 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 : 输入A数组: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释 ...
- [置顶] Android 应用内禁止截屏功能的实现
截图介绍 Android的调试工具DDMS提供有截屏功能,很多软件也会有截屏功能,在做支付等安全类应用的时候,为了保证用户的资产和系统安全,往往会禁止应用内截屏,禁止之后,在此应用处于前台的情况下 ...
- yii框架:CDbConnection failed to open the DB connection: could not find driver的解决的方法
这个问题是由于php中缺少pdo mysql造成的. 解决方法是为php加入此扩展.前往你最早的php安装文件,进入ext/pdo_mysql/文件夹下,然后./configure --with-ph ...
- (学习笔记3)BMP位图的读取与显示
在(学习笔记2)中.我们已经具体说明怎样去创建MFC.在这节中.主要解决BMP位图照片的读取和显示问题. 我们新建一个projectdemo1.创建步骤请看(学习笔记2)中具体说明. 创建成功后,例如 ...
- overflow滚动条样式设置,ie和webkit内核
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Nginx 第三方模块的安装以及一致性哈希算法的使用
Nginx 第三方模块的安装以及一致性哈希算法的使用 第三方模块安装方法总结: 以ngx_http_php_memcache_standard_balancer-master为例 1:解压 到 pat ...
- jquery的一点点认识
概述 JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 .它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, O ...
- FFmpeg源码简单分析:结构体成员管理系统-AVOption
===================================================== FFmpeg的库函数源码分析文章列表: [架构图] FFmpeg源码结构图 - 解码 FFm ...
- Fckeditor常见漏洞的挖掘与利用整理汇总
查看编辑器版本号 FCKeditor/_whatsnew.html ------------------------------------------------------------- 2. V ...
- kubernetes集群管理常用命令一
系列目录 我们把集群管理命令分为两个部分,第一部分介绍一些简单的,但是可能是非常常用的命令以及一些平时可能没有碰到的技巧.第二部分将综合前面介绍的工具通过示例来讲解一些更为复杂的命令. 列出集群中所有 ...