当前位置:网站首页>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
边栏推荐
- Expansion method of unity scanning circle
- 【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
- Unity supports the platform # define instruction of script
- PKCs 12:personal information exchange syntax v1.1 translation part I
- Question mark (?) in Cron expression Use of
- 14x1.5cm竖向标签有点难,VFP调用BarTender来打印
- [typescript] cannot redeclare block range variables
- Ugui uses its own function to realize reverse mask
- The minecraft server address cannot be refreshed.
- 如何写论文
猜你喜欢

Use the code cloud publicholiday project to determine whether a day is a working day

Responding with flow layout

The file has been downloaded incorrectly!

14x1.5cm vertical label is a little difficult, VFP calls bartender to print

Unity 3D model operation and UI conflict Scrollview

【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example

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

Unity + hololens common basic functions
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

Super comprehensive summary | related improvement codes of orb-slam2 / orb-slam3!
随机推荐
终端便捷ssh(免密)连接
如何写论文
The file has been downloaded incorrectly!
Another download address for typro
Unity profiler performance analysis
How can the international trading platform for frying US crude oil guarantee capital security?
Detailed explanation of the loss module of mmdet
Chinese pycharm changed to English pycharm
遥感图像/UDA:Curriculum-Style Local-to-Global Adaptation for Cross-Domain Remote Sensing Image Segmentat
Question mark (?) in Cron expression Use of
How to judge the quality of network transformer? What symptom is network filter transformer broken?
Unity3d- use animator and code to control task walking
《谁动了我的奶酪》读后感
Pytorch的安装以及入门使用
Tensorflow2 of ubantu18.04 X installation
Parkour demo
2021-06-17 solve the problem of QML borderless window stretching, window jitter and flicker when stretching and shrinking
Set a plane to camera viewport
Unit asynchronous jump progress
[recruitment] UE4 Development Engineer