当前位置:网站首页>Codeforces Round #742 (Div. 2) F. One-Four Overload
Codeforces Round #742 (Div. 2) F. One-Four Overload
2022-06-11 21:25:00 【dplovetree】
F. One-Four Overload
The question :
Here you are. n ∗ m n*m n∗m The grid of , n < = 500 , m < = 500 n<=500,m<=500 n<=500,m<=500, Some lattices are ‘X’, Some lattices are ‘.’, The problem is to ensure that the outermost circle of the grid is ‘.’, Now we need to be in ‘.’ Filled in the grid of 1 perhaps 0,‘X’ Value on , It's up, down, left and right , In four directions ‘.’ The weight sum of the lattice of .
Ask if there is a color scheme , Make all ‘X’ The values on the grid are 5 Multiple . Some words , Output construction scheme .
Ideas :
An obvious idea , We are in accordance with the ‘X’ The grid is in four directions ‘.’ The quantity classification of the lattice .
If 0, So give it to ’X’ Lattice assignment 0 ;
If 1 or 3, No matter how you fill in the numbers, it is impossible to achieve 5 Multiple .
If it is 2, Then only one of those two boxes can be filled 1, One to fill in 4;
If it is 4, Then you can only fill in two 1, Two 4;
consider 4 How to fill in the information of , If the color on the top is the same as the color on the left , So for the one in the upper left corner ’X’, If there are only two around him , Then you are not satisfied . On such consideration , We call a quantity 4 Lattice of , Fill in a number above and below , Fill in a number on the left and right , This ensures that the upper left 、 The lower left , The upper right 、 The sum of the four aspects at the bottom right is 5 Multiple .
Now it looks like , Still not able to handle . But we can see , For a lattice , It can only be filled in 1 or 4, And once you fill in a number , So the corresponding , The following figures are the only ones to be determined . I really want to color the graph , Use black and white to color the picture , Adjacent dots are dyed in different colors , You can simply think of , No matter what number you fill in first , It doesn't affect . So let's create a picture to dye .
( It's very convenient to handle it like this , My first thought was to put a ‘X’ , One ‘.’ Such a connected graph is deducted , Re staining , It is easy to write in black and white , It's easy to understand );
Code :
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
vector<int>v[300050];
int d[][2]={
1,0,0,1,-1,0,0,-1};
char mp[505][505];
int ans[300050]={
0};
int id(int x,int y){
return (x-1)*m+y;
}
int cnt(int x,int y){
int res=0;
for(int i=0;i<4;i++){
int nx=x+d[i][0];
int ny=y+d[i][1];
if(mp[nx][ny]=='.')res++;
}
return res;
}
int f=1;
void dfs(int x,int w){
ans[x]=w;
for(int i=0;i<v[x].size();i++){
if(!ans[v[x][i]])
dfs(v[x][i],5-w);
if(ans[v[x][i]]==ans[x])f=0;
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>mp[i]+1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='X'){
int res=cnt(i,j);
if(res==2){
ans[id(i,j)]=5;
int now=-1;
for(int k=0;k<4;k++){
int nx=i+d[k][0];
int ny=j+d[k][1];
if(mp[nx][ny]=='.'){
if(now==-1)now=id(nx,ny);
else {
v[now].push_back(id(nx,ny));
v[id(nx,ny)].push_back(now);
}
}
}
}else if(res==4){
ans[id(i,j)]=10;
v[id(i-1,j)].push_back(id(i,j-1));
v[id(i-1,j)].push_back(id(i,j+1));
v[id(i+1,j)].push_back(id(i,j+1));
v[id(i+1,j)].push_back(id(i,j-1));
v[id(i,j-1)].push_back(id(i-1,j));
v[id(i,j+1)].push_back(id(i-1,j));
v[id(i,j+1)].push_back(id(i+1,j));
v[id(i,j-1)].push_back(id(i+1,j));
}else if(res==0){
ans[id(i,j)]=0;
}else if(res%2==1){
printf("NO\n");
return 0;
}
}
}
}
f=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mp[i][j]=='.'&&!ans[id(i,j)])
dfs(id(i,j),4);
}
}
if(!f)cout<<"NO"<<endl;
else{
cout<<"YES\n"<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)cout<<ans[id(i,j)]<<" ";
cout<<endl;
}
}
return 0;
}
边栏推荐
- JUnit tests multithreaded code, and the sub thread does not run
- Realize the same length of tablayout subscript and text, and change the selected font size
- select _ Lazy loading
- Common file functions
- Field queryIndexFieldnameService in xxxImpl required a single bean, but 19 were found:
- Goto statement of go language
- 【C语言进阶】整型在内存中的存储
- JVM heap
- JVM之堆区
- Educational Codeforces Round 111 (Rated for Div. 2) C 补题
猜你喜欢

Use float to create a page header, footer, left content, and main content.

ORA-04098: trigger ‘xxx. xxx‘ is invalid and failed re-validation

关于斜率优化

Test plans and test cases

Jenkins+allure integrated report construction

Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system

Tensorflow 2. X Getting Started tutorial

Syntax of SQL

JVM|虚拟机栈(局部变量表;操作数栈;动态链接;方法的绑定机制;方法的调用;方法返回地址)

Software test plan
随机推荐
My collection of scientific research websites
How to create the simplest SAP kyma function
JVM之堆区
Goto statement of go language
Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system
select _ Lazy loading
BUG -- coredump使用
Serval and Rooted Tree(CF1153D)-DP
JVM|类加载器;双亲委派机制
A problem of setting the private library of golang
flutter系列之:flutter中常用的container layout详解
[Game Theory - introduction]
Analysis on the development history and market development status of China's system integration industry in 2020 [figure]
Codeforces Round #742 (Div. 2) F. One-Four Overload
Obsidian关系图谱如何让节点可以手动拖动
二分图King
Flutter implements the JD address selection component
如何创建最简单的 SAP Kyma Function
Syntax of SQL
apache 本地多端口配置