当前位置:网站首页>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
边栏推荐
- Unityshader learning notes - Basic Attributes
- 【LeetCode】Easy | 225. Using queue to realize stack (pure C manual tearing queue)
- GoLand No Tests Were Run : 不能使用 fmt.Printf() &lt;BUG&gt;
- Chapter 11 advanced data management of OpenGL super classic (version 7)
- Unity- the camera follows the player
- East Tower attack and defense world - XSS bypasses the safety dog
- [vcs+verdi joint simulation] ~ take the counter as an example
- Unity limited time use limited trial time and use times
- Nestjs入门和环境搭建
- pytorch中常用损失函数总结
猜你喜欢

QT connecting external libraries

Access is denied encountered when vfpbs calls excel under IIS
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

Unity project hosting platform plasticscm (learn to use 1)

Unity scroll view element drag and drop to automatically adsorb centering and card effect

3D rotation album

Rotation, translation and scaling of unity VR objects

Connect() and disconnect() of socket in C #
![[notes] unity webgl input Chinese](/img/f7/805f510ff691227b4c2b529cc1099a.jpg)
[notes] unity webgl input Chinese

Some problems encountered in unity steamvr
随机推荐
Intellj idea generates jar packages for projects containing external lib to other projects. The method refers to the jar package written by itself
Super comprehensive summary | related improvement codes of orb-slam2 / orb-slam3!
Chapter 9 of OpenGL super classic (version 7): fragment processing and frame buffering
PWN Introduction (2) stack overflow Foundation
Ugui uses its own function to realize reverse mask
[typescript] cannot redeclare block range variables
东塔攻防世界—xss绕过安全狗
【LeetCode】Easy | 232. Using stack to realize queue (pure C manual tearing stack)
Gradient clip in dqn
Nestjs配置静态资源,模板引擎以及Post示例
Procedural animation -- inverse kinematics of tentacles
Use the code cloud publicholiday project to determine whether a day is a working day
Revit二次開發---未打開項目使用面板功能
Summary of common loss functions in pytorch
Unity mobile end sliding screen rotation
Unit asynchronous jump progress
Unity 3D model operation and UI conflict Scrollview
很紧张,第一天做软件测试,需要做什么?
Unity dotween plug-in description
Unity3d packaging and publishing APK process