题目传送门

 1 /*
 2     模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0
 3     很挫的判断四个方向是否OK
 4 */
 5 #include <cstdio>
 6 #include <iostream>
 7 #include <algorithm>
 8 #include <cmath>
 9 #include <cstring>
10 #include <map>
11 using namespace std;
12
13 const int MAXN = 1e3 + 10;
14 const int INF = 0x3f3f3f3f;
15 int a[MAXN][MAXN];
16
17 bool lose(int i, int j, int n, int m)
18 {
19     if (a[i][j] == 1)
20     {
21         if (j < m && a[i][j+1] == 1)
22         {
23             if (i < n && a[i+1][j] == 1)
24             {
25                 if (a[i+1][j+1] == 1)
26                 {
27                     return true;
28                 }
29             }
30         }
31         if (j>1 && a[i][j-1] == 1)
32         {
33             if (i < n && a[i+1][j-1] == 1)
34             {
35                 if (a[i+1][j] == 1)
36                 {
37                     return true;
38                 }
39             }
40         }
41         if (j > 1 && a[i][j-1] == 1)
42         {
43             if (i > 1 && a[i-1][j-1] == 1)
44             {
45                 if (a[i-1][j] == 1)
46                 {
47                     return true;
48                 }
49             }
50         }
51         if (j < m && a[i][j+1] == 1)
52         {
53             if (i > 1 && a[i-1][j] == 1)
54             {
55                 if (a[i-1][j+1] == 1)
56                 {
57                     return true;
58                 }
59             }
60         }
61     }
62
63     return false;
64 }
65
66 int main(void)
67 {
68     #ifndef ONLINE_JUDGE
69         freopen ("A.in", "r", stdin);
70     #endif
71
72     int n, m, k;
73     while (~scanf ("%d%d%d", &n, &m, &k))
74     {
75         memset (a, 0, sizeof (a));
76
77         bool flag = false;    int ans = -1;
78         for (int i=1; i<=k; ++i)
79         {
80             int x, y;
81             scanf ("%d%d", &x, &y);
82             if (a[x][y] == 1)    continue;
83
84             a[x][y] = 1;
85             if (lose (x, y, n, m) && !flag)
86             {
87                 flag = true;    ans = i;
88             }
89         }
90
91         if (!flag)    printf ("%d\n", 0);
92         else    printf ("%d\n", ans);
93     }
94
95     return 0;
96 }

转载于:https://www.cnblogs.com/Running-Time/p/4366604.html

模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels相关推荐

  1. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C 1 /* 2 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 3 模拟题:蛮恶心的 ...

  2. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <al ...

  3. CodeForces Round #288 Div.2

    A. Pasha and Pixels (水题 暴力) 题意: 有一个n×m的矩阵,最开始所有的格子都是白色的. 一个人按照某种顺序将格子涂成黑的,如果某个格子已经是黑的则忽略.在涂色的过程中如果出现 ...

  4. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

  5. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

  6. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  7. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and Phone Pasha has recently bought a new phone jPager and started adding his friends' phon ...

  8. Codeforces Round #656 (Div. 3) F. Removing Leaves 贪心 + 模拟

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个贪心策略就是每次都找一个叶子节点最多的点,让后删掉他的kkk个叶子节点,现在我们就来考虑如何模拟这个过程. 我们整一个vector<s ...

  9. Codeforces Round #249 (Div. 2) (模拟)

    Codeforces Round #249 (Div. 2) (模拟) C. Cardiogram time limit per test 1 second memory limit per test ...

最新文章

  1. ES mapping可以修改include_in_all,也可以修改index_options,norm,但是无法修改_all属性!...
  2. 浅析Java.lang.ProcessBuilder类
  3. python udp创建addr_一篇文章搞定Python 网络编程之UDP协议
  4. mfc socket onreceive函数不被调用_不报错地调用空指针类的成员函数
  5. 安卓案例:表达式计算器
  6. android des ecb加密_Android逆向 | 基础知识篇 01
  7. 华为ac配置radius认证服务器_华为AAA结合Radius服务器认证学习
  8. PCIe总线协议概述
  9. iPhone app 和android app开发环境和语言的区别
  10. 【深度好文】二维图像傅里叶变换 YYDS
  11. html位置插入透明动画文字,鼠标放上去,图片上方动态显示半透明说明文字(源码)...
  12. 淘宝联盟api对接,实现优惠券查询功能
  13. #2014蓝桥杯-4.史丰收速算--------根本看不懂
  14. emacs快捷键总结
  15. FFmpeg 源码导读 —— H264码流格式分析
  16. Oracle LiveLabs实验:Application Continuity Fundamentals
  17. 【IntelliJ IDEA】idea修改文件的file is read-only
  18. 用AOMEI Partition Assistant制作PE 启动盘
  19. 计算机网络基础基本知识
  20. 产品经理和项目经理谁才是项目管理界的NO.1?

热门文章

  1. JS面向对象——原型式继承函数、寄生式继承函数、寄生组合式继承
  2. LeetCode 1871. 跳跃游戏 VII(贪心)
  3. LeetCode 1037. 有效的回旋镖
  4. LeetCode 1005. K 次取反后最大化的数组和
  5. LeetCode 888. 公平的糖果交换(哈希set)
  6. python获取股票数据_python根据股票代码获取当前数据
  7. 完全相同的4个小矩形如图所示放置_吸睛!矩形在PPT中的创意表现
  8. Ubuntu Linux系统下搭建自己的Web服务器
  9. 4.数据库(增删改查)备份及恢复
  10. centos6.5装mysql好难_CentOS6.5 下MySQL傻瓜式安装