模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
生活随笔
收集整理的這篇文章主要介紹了
模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
題目傳送門
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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle 直方图理论
- 下一篇: CSS3滤镜