模拟 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的黑色矩阵.直接模拟即可 代码: ...
随机推荐
- September 25th 2016 Week 40th Sunday
Everything is good in its season. 万物逢时皆美好. Don't lose hope. Remeber that even a dog has its day. Onc ...
- C#资源文件管理
1.右键项目点属性; 2.点资源项,添加资源下拉框的添加现在文件,如下图: 3.直接上代码获取并复制到指定文件夹下: private void button1_Click(object sender, ...
- NPOI基本操作XLS
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...
- solrconfig.xml和schema.xml说明
1. solrconfig.xml solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置. 1.1. datadir节点 ...
- ios Push证书 转换步骤
1.将aps_developer_identity.cer转换成aps_developer_identity.pem格式openssl x509 -in aps_developer_identity. ...
- Android开发环境搭建:离线安装ADT插件和安装SDK
一.准备 在线安装SDK较慢,在此我选择了离线安装,所需要的工具下载:http://yun.baidu.com/share/link?shareid=2286446004&uk=2000812 ...
- Xcode常用代码块
Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带来很大的方便. 常用的: 1.strong:@property (nonatomic,stron ...
- NYOJ题目64鸡兔同笼
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsAAAAIZCAIAAAAnfB5fAAAgAElEQVR4nO3dO1LjygIG4LsJchZC7I ...
- SQL常用查询语句及函数
1.日期匹配_获取时间差 select datediff(dd,getdate(),'12/25/2006') --计算从今天到12/25/2006还有多少个月 2.不能通过IP连接数据库 在数据库 ...
- 面试题之【打印1到最大的N位数】
题目描述:给定一个数字N,打印从1到最大的N位数. 看起来像是很简单的问题(虽然实际也不是很难...)我们很容易写出这样的代码: #include<iostream> #include&l ...