模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
/*
模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0
很挫的判断四个方向是否OK
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN]; bool lose(int i, int j, int n, int m)
{
if (a[i][j] == )
{
if (j < m && a[i][j+] == )
{
if (i < n && a[i+][j] == )
{
if (a[i+][j+] == )
{
return true;
}
}
}
if (j> && a[i][j-] == )
{
if (i < n && a[i+][j-] == )
{
if (a[i+][j] == )
{
return true;
}
}
}
if (j > && a[i][j-] == )
{
if (i > && a[i-][j-] == )
{
if (a[i-][j] == )
{
return true;
}
}
}
if (j < m && a[i][j+] == )
{
if (i > && a[i-][j] == )
{
if (a[i-][j+] == )
{
return true;
}
}
}
} return false;
} int main(void)
{
#ifndef ONLINE_JUDGE
freopen ("A.in", "r", stdin);
#endif int n, m, k;
while (~scanf ("%d%d%d", &n, &m, &k))
{
memset (a, , sizeof (a)); bool flag = false; int ans = -;
for (int i=; i<=k; ++i)
{
int x, y;
scanf ("%d%d", &x, &y);
if (a[x][y] == ) continue; a[x][y] = ;
if (lose (x, y, n, m) && !flag)
{
flag = true; ans = i;
}
} if (!flag) printf ("%d\n", );
else printf ("%d\n", ans);
} return ;
}
模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels的更多相关文章
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...
- Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和
Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- 模拟 Codeforces Round #203 (Div. 2) C. Bombs
题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
- Codeforces Round #288 (Div. 2)
A. Pasha and Pixels 题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: ...
随机推荐
- August 10th, 2016, Week 33rd, Wednesday
The degree of loving is measured by the degree of giving. 爱的深浅是用给与的多少来衡量的. Some say that if you love ...
- CUDA中Bank conflict冲突
转自:http://blog.csdn.net/smsmn/article/details/6336060 其实这两天一直不知道什么叫bank conflict冲突,这两天因为要看那个矩阵转置优化的问 ...
- 隐藏<input type="file"> 实现点击div或图片打开文件选择路径
HTML: <input type="file" style="display:none" id="addfile-btn"> ...
- Angular.JS
AngularJS是什么? 完全使用 JavaScript编写的客户端技术.同其他历史悠久的 Web技术( HTML. CSS 和JavaScript)配合使用,使Web应用开发比以往更简单.更快捷. ...
- Swift - 获取、改变按钮的标题文本(UIButton点击切换title)
在开发中,我们常常需要动态地改变按钮标签文字,使用 setTitle() 函数就可以了.有时我们需要在几个标题间切换,比如下面样例所示,按钮点击后按钮文字会在"播放""暂 ...
- 直接放个DB2 SQL STATEMENT大全好了!
SQL statements This topic contains tables that list the SQL statements classified by type. SQL sch ...
- Jmeter测试JDBC
Datebase Driver class Database URL MySQL com.mysql.jdbc.Driver jdbc:mysql://host:port/{dbname} Postg ...
- HTML5 – 2.新元素
figcaption 定义和用法 <figcaption> 标签定义 figure 元素的标题(caption). "figcaption" 元素应该被置于 " ...
- MVC - 11(下)jquery.tmpl.js +ajax分页
继续 mvc-11(上).dto:http://www.cnblogs.com/tangge/p/3840060.html jquery.tmpl.js 下载:http://pan.baidu.com ...
- Redis笔记(五)Redis的事务
>>关系型数据库的事务 事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消. Atomic(原子性): 一个事务(transaction)中的 ...