这题能贪心吗,我的做法wa2,玄关
查看原帖
这题能贪心吗,我的做法wa2,玄关
1134329
long_ting楼主2024/3/1 14:23
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pii;


#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define int long long
#define mod 998244353







void solve(){
	char c[20][20];	
	int b[20][20];
	int ans=0;
	for(int i=1;i<=7;i++)
		for(int j=1;j<=7;j++)
			cin>>c[i][j];
	
	while(1){
		int flag=0;
		for(int i=1;i<=7;i++)
			for(int j=1;j<=7;j++)
				b[i][j]=0;
		for(int i=1;i<=7;i++)
			for(int j=1;j<=7;j++){
			if(i>=2&&j>=2&&i<=6&&j<=6&&c[i+1][j+1]=='B'&&c[i+1][j-1]=='B'&&c[i-1][j+1]=='B'&&c[i-1][j-1]=='B'&&c[i][j]=='B'){
				b[i+1][j+1]++;
				b[i+1][j-1]++;
				b[i-1][j+1]++;
				b[i-1][j-1]++;
				b[i][j]++;
				flag=1;
			}
		}
		if(!flag) break;
		int Max=0,idxx=0,idxy=0;
		for(int i=1;i<=7;i++)
			for(int j=1;j<=7;j++){
				if(b[i][j]>Max) {
					Max=b[i][j];
					idxx=i,idxy=j;
				}
			}
		ans++;
		c[idxx][idxy]='W';

	}
	/*for(int i=1;i<=7;i++){
	
		for(int j=1;j<=7;j++){
			cout<<c[i][j];
		}
		cout<<"\n";
	}*/
	cout<<ans<<"\n";
	/*
1
BBBBBBB
BBBBBBB
BBBBBBB
BBBBBBB
BBBBBBB
BBBBBBB
BBBBBBB


	*/
}

signed main(){
	IOS;
	int t=1;
    cin>>t;
	while(t--){
		solve();
        //cout<<"-------------------------"<<endl;
	}
	return 0;

}

我的想法是先统计每个点在多少个"X"当中,每次选取出现次数最大的那个点,将其改为W

2024/3/1 14:23
加载中...