当前位置:网站首页>D. Big Brush
D. Big Brush
2022-06-30 05:21:00 【whitewall_ nine】
// Problem: D. Big Brush
// Contest: Codeforces - Codeforces Round #771 (Div. 2)
// URL: https://codeforces.com/contest/1638/problem/D
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 2022-02-15 20:19:54
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
const int N = 1e3 + 10;
int n, m;
int a[N][N];
int ans[N * N][3];
bool used[N][N];
int cc[N];
int cnt;
void check (int x, int y) {
if (x < 0 || x + 1 >= n || y < 0 || y + 1 >= m) return;
if (used[x][y]) return;
int sz = 0;
for (int i = 0; i < 2; i ++) {
for (int j = 0; j < 2; j ++) {
int c = a[x + i][y + j];
if (c != -1) {
cc[sz++] = c;
}
}
}
if (sz == 0) return;
sort(cc, cc + sz);
if (cc[0] != cc[sz - 1]) return;
ans[cnt][0] = x;
ans[cnt][1] = y;
ans[cnt][2] = cc[0];
used[x][y] = 1;
cnt++;
}
void solve() {
scanf("%d%d", & n, & m);
for (int i = 0 ; i< n; i ++) {
for (int j = 0; j < m; j ++)
scanf("%d", & a[i][j]);
}
for (int i = 0; i < n - 1; i++)
for (int j =0; j < m - 1; j++)
check(i, j);
for (int i = 0; i < cnt;i ++) {
int x = ans[i][0], y = ans[i][1];
a[x][y] = a[x + 1][y] = a[x + 1][ y + 1] = a[x][y + 1] = -1;
for (int j = -1; j <= 1; j++) {
for (int k = -1; k <= 1; k ++) {
check(x + j, k + y);
}
}
}
bool ok = 1;
for (int i = 0; i < n; i ++)
for (int j = 0; j < m ;j ++)
ok &= a[i][j] == -1;
if (!ok) {
puts("-1");
return;
}
printf("%d\n",cnt);
for (int i = cnt - 1; i >= 0; i --)
printf("%d %d %d\n", ans[i][0] + 1, ans[i][1] + 1, ans[i][2]);
}
int main () {
solve();
// int t;
// t = 1;
// while (t --) solve();
return 0;
}
By enumerating the last operation , The last operation must be four squares of the same color . And then you can push back through this square , By querying the square containing any one of the squares . Then judge whether the colors inside are the same , If it's all the same , Then it can be used as the second step , Push class by this . This question is mainly about reverse thinking Why not ? Because we didn't find that after removing the current square , Just judge whether the colors in other squares are the same , There is no need to judge every stain . That's too much trouble . In the future, we should understand the nature
边栏推荐
- Unity project hosting platform plasticscm (learn to use 2)
- Introduction to mmcv common APIs
- Chapter 12 pipeline monitoring of OpenGL super classic (version 7)
- Virtual and pure virtual destructions
- Unity application class and data file path
- Unity packaging and publishing webgl error reason exception: failed building webgl player
- Visualization of 3D geological model based on borehole data by map flapping software
- Log writing specification
- PKCs 12:personal information exchange syntax v1.1 translation part I
- MinGW-w64下载文件失败the file has been downloaded incorrectly!
猜你喜欢

虚析构和纯虚析构

Database base (Study & review for self use)
![[learning notes] AssetBundle, xlua, hot update (use steps)](/img/59/9d9f31cfe55a908f2f0705e95ecc05.jpg)
[learning notes] AssetBundle, xlua, hot update (use steps)

Summary of common loss functions in pytorch

3D rotation album

Ugui uses its own function to realize reverse mask

The file has been downloaded incorrectly!

mmcv常用API介绍

企事业单位源代码防泄露工作该如何进行

【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
随机推荐
【VCS+Verdi聯合仿真】~ 以計數器為例
终端便捷ssh(免密)连接
Unity + hololens2 performance test
Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
Gradient clip in dqn
[typescript] cannot redeclare block range variables
Visualization of 3D geological model based on borehole data by map flapping software
Unity packaging and publishing webgl error reason exception: failed building webgl player
Unity + hololens common basic functions
《谁动了我的奶酪》读后感
Some problems encountered in unity steamvr
14x1.5cm vertical label is a little difficult, VFP calls bartender to print
C # uses monopinvokecallback to directly call back C # function
Unity ugui text value suspended enlarged display add text background
[vcs+verdi joint simulation] ~ take the counter as an example
Nestjs configures static resources, template engine, and post examples
Fifty years ago, the go code first submitted by the inventor of Hello world was as long as this
pytorch中常用损失函数总结
Very nervous. What should I do on the first day of software testing?
企事业单位源代码防泄露工作该如何进行