神奇做法

P1162 填涂颜色

orz
by WsW_ @ 2023-12-03 09:22:13



by sir_carrot @ 2024-02-21 10:41:08


巧了,我也是这么做的,但是不是很长,只是你太暴力了
by wantto123 @ 2024-04-13 20:45:12


``` #include<bits/stdc++.h> using namespace std; int n,ma1[32][32],ma2[32][32]; int walk[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; int main(){ cin>>n; int tot=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>ma1[i][j]; ma2[i][j]=ma1[i][j]; } } for(int u=0;u<=30;u++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(ma1[i][j]==0){ for(int k=0;k<4;k++){ int xx=i+walk[k][0]; int yy=j+walk[k][1]; if(ma1[xx][yy]==3||xx<1||xx>n||yy<1||yy>n){ ma1[i][j]=3; } } } } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(ma1[i][j]==0){ cout<<2<<' '; } else cout<<ma2[i][j]<<' '; } cout<<endl; } return 0; } ```
by wantto123 @ 2024-04-13 20:45:34


|