https://nanti.jisuanke.com/t/A1537
I also used the time to write before the set time-out has been removed just fine
#include<bits/stdc++.h> using namespace std; char mp[1005][1005]; int fx[8]={0,1,0,-1,1,1,-1,-1}; int fy[8]={1,0,-1,0,1,-1,-1,1}; int a[600]; intK1; struct Node { int X1, Y1; } Qu [ 10005 ]; int Check ( int ANS) { int I, J; Map < int , int > m; Vector < int > VE; for (I = 0 ; I < K1; I ++) // live queue each discharge position to take out his next mark + 1'd { Node Q = Qu [I]; ve.push_back (q.x1 * 10000 + q.y1); // Also note that , save what each point is the first 27 lines of code for (J =0 ; J < . 8 ; J ++ ) { int XXX q.x1 = FX + [J], yyy = q.y1 + FY [J]; m [XXX * 10000 + yyy] ++ ; } } for (I = 0 ; I <ve.size (); I ++ ) { int C = VE [I]; IF (m [C] == 0 ) m [C] = . 1 ; // if no live next to him are also put him map in order to cut it (referred to as 1 next to it because if only one still alive he would die) } K1 = 0 ; map < int , int >::iterator it; for(it=m.begin();it!=m.end();it++) { int f=it->first,s=it->second; int xxx=f/10000,yyy=f%10000; if(mp[xxx][yyy]=='#') { if(s<2||s>3)mp[xxx][yyy]='.',ans--; else if(s>=2&&s<=3)qu[k1].x1=xxx,qu[k1++].y1=yyy; } else { if(s==3) { mp[xxx][yyy]='#',ans++; qu[k1].x1=xxx,qu[k1++].y1=yyy; } } } return ans; } int main() { int i,j,t; scanf("%d",&t); while(t--) { int n,m; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); getchar(); k1=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%c",&mp[i+500][j+500]); if(mp[i+500][j+500]=='#')a[0]++,qu[k1].x1=i+500,qu[k1++].y1=j+500; } getchar(); } int minn=a[0],mi=0; for(int k=1;k<=321;k++) { a[k]=check(a[k-1]); if(a[k]>minn) { minn=a[k],mi=k; } } for(i=0;i<k1;i++) { node q=qu[i]; if(mp[q.x1][q.y1]=='#')mp[q.x1][q.y1]='.';//初始化 } cout<<mi<<" "<<minn<<" "<<a[321]<<endl; } return 0; }