当前位置:网站首页>3371. comfortable cow
3371. comfortable cow
2022-06-22 01:13:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
List of articles
3371. Comfortable cow
The question
Farmer John The grassland can be regarded as a huge two-dimensional matrix composed of square squares ( Imagine a huge chessboard ).
At the beginning , The grass is empty .
Farmer John Will... One by one N A cow joined the grass .
The first i A cow will occupy the square (xi,yi), Unlike all the squares that have been occupied by other cows .
A cow is called 「 comfortable 」, If it is horizontally or vertically adjacent to exactly three other cows .
Farmer John Interested in the number of comfortable cows on his farm .
Yes 1…N Each of them i, Output No i The number of comfortable cows after a cow is added to the grass .Ideas
Every time a point is added , Only four surrounding points will be affected , Enumerate whether these four points are occupied , If occupied, update the status
Code
/* * @Author: NEFU AB-IN * @Date: 2022-06-21 15:39:07 * @FilePath: \ACM\Acwing\3371\3371.cpp * @LastEditTime: 2022-06-21 16:09:10 */ #include <bits/stdc++.h> using namespace std; #define int long long #define SZ(X) ((int)(X).size()) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DEBUG(X) cout << #X << ": " << X << endl; typedef pair<int, int> PII; const int INF = INT_MAX; const int N = 1e3 + 10; int st[N][N]; int vis[N][N]; int dir[5][2] = { { 0, 1}, { 0, -1}, { 1, 0}, { -1, 0}, { 0, 0}}; signed main() { IOS; int n, cnt = 0; cin >> n; auto judge = [&](int x, int y) { int cnt = 0; for (int i = 0; i < 4; ++i) { int x1 = x + dir[i][0]; int y1 = y + dir[i][1]; if (x1 >= 0 && y1 >= 0 && st[x1][y1]) cnt += 1; } if (!vis[x][y] && cnt == 3) { vis[x][y] = 1; return 1; } else if (vis[x][y]) { vis[x][y] = 0; return -1; } return 0; }; while (n--) { int x, y; cin >> x >> y; st[x][y] = 1; for (int i = 0; i < 5; ++i) { int x1 = x + dir[i][0]; int y1 = y + dir[i][1]; if (x1 >= 0 && y1 >= 0 && st[x1][y1]) cnt += judge(x1, y1); } cout << cnt << '\n'; } return 0; }
边栏推荐
- [dailyfresh] course record 3 -- product search related
- Chapter VIII exercises (45A) [microcomputer principles] [exercises]
- 如何使用物联网低代码平台进行报表管理?
- Small protocol with great power, why can't digital transformation without nvme full flash memory?
- [Environmental stepping pit] pycharm reports an error when using QT
- 判断系统CPU是否空闲
- [redis] install redis in Ubuntu and the basic usage and configuration of redis
- Pre add post add exploration and function call exploration
- Leetcode做题目录
- 对知识图谱与深度学习的关系理解
猜你喜欢

Spark RDD案例:词频统计

Sparkrdd case: calculate total score

4G/wifi 能耗计量插座-监测电压电流功率
![[dailyfresh] course record 3 -- product search related](/img/54/e1dbc6c2a6bd6d1f39de0f55d79976.png)
[dailyfresh] course record 3 -- product search related

How the conductive slip ring works

pytorch学习09:矩阵基本运算

pytorch学习07:Broadcast广播——自动扩展

Using SSM framework to realize user login

pytorch学习02:手写数字识别

Pytorch learning 06: tensor dimension transformation
随机推荐
English语法_副词 - loud /aloud / loudly
12 initialization of beautifulsoup class
4273. 链表合并
Tensorflow environment setup
HDOJ - Is It A Tree?
Pytorch learning 03: tensor data types and some operations
Pytorch learning 10: statistical operations
答应我, 不要再用 if (obj != null) 判空了
0x00007ffff3d3ecd0 in _IO_vfprintf_internal (s=0x7ffff40b5620 <_IO_2_1_stdout_>
Pytorch learning 08: splicing and splitting
面试题目录收集
判断系统CPU是否空闲
[GLib][GStreamer] 插件编写思路 —— 继承、覆写 和 虚函数
【环境踩坑】pycharm使用qt时报错
Sqlite3数据库的timestamp类型的使用注意事项
MSVC与GCC的差异(收集中)
How to judge pure IP? Where can I find it? Is it Expensive?
[GStreamer] 插件编写 —— Test程序
PAT(甲) - 1001 A+B Format
[dailyfresh] problems encountered in sending activation email