玄学做法60分3TLE
查看原帖
玄学做法60分3TLE
370191
火星─002楼主2021/4/10 22:28

rt

#include<bits/stdc++.h>//false==0,true==1
using namespace std;
char mother[1001][1001];
int n,m,a[1001][1001],b[100000][2];
bool state[1001][1001];
const int I=0,J=1;
void bfs()
{
	bool time_short=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(state[i][j]==1)
			{
				if(a[i][j+1]==!a[i][j]&&!state[i][j+1])state[i][j+1]=1,time_short=0;
				if(a[i][j-1]==!a[i][j]&&!state[i][j-1])state[i][j-1]=1,time_short=0;
				if(a[i+1][j]==!a[i][j]&&!state[i+1][j])state[i+1][j]=1,time_short=0;
				if(a[i-1][j]==!a[i][j]&&!state[i-1][j])state[i-1][j]=1,time_short=0;
			}
		}
	//for(int i=1;i<=n;i++,cout<<endl)for(int j=1;j<=n;j++)cout<<state[i][j];cout<<endl;
	if(time_short==0)bfs();
	else return;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>mother[i][j],a[i][j]=mother[i][j]-'0';
	for(int k=1;k<=m;k++)cin>>b[k][I]>>b[k][J];
	int k=1;
	while(k<=m)
	{
		for(int i=1;i<=n/2;i++)for(int j=1;j<=n/2;j++)
		state[i][j]=0,state[n-i+1][n-j+1]=0,state[n-i+1][j]=0,state[i][n-j+1]=0;
		state[b[k][I]][b[k][J]]=1;
		bfs();
		int ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(state[i][j]==1)ans++;
		cout<<ans<<'\n';
		k++;
	}
}

麻烦各位看看可还有救,没救我就放弃这段代码了。

2021/4/10 22:28
加载中...