60分求助。。。感谢大佬
查看原帖
60分求助。。。感谢大佬
97287
小胖同学楼主2022/9/22 23:22
#include<bits/stdc++.h>
using namespace std;
#define 小臧同学 main
#define ll long long
int go[2][8] = {{1  , 1 , -1 , -1 , 2 , 2 , -2 , -2} , {2 , -2 , 2 , -2 , 1 , -1 , 1 , -1}};
int mp[201][201];
int n , ans;
int col[40040] , vis[40040];
struct Node{
	int next , to;
}e[1000401];
int cnt , h[40040];
inline int Get_Id(int x , int y){return x * n + y - n;}
inline void add(int a , int b){e[++ cnt].to = b , e[cnt].next = h[a] , h[a] = cnt;}
void Init(){
	cin >> n;
	char c;
	for(int i = 1;i <= n;++ i)
		for(int j = 1;j <= n;++ j){
		cin >> c;
		ans += !(c - '0');
		mp[i][j] = !(c - '0');
	}
	// 每个点对外建单向边
	for(int i = 1;i <= n;++ i)
		for(int j = 1;j <= n;++ j)
		if(mp[i][j])
			for(int k = 0;k < 8;k ++){
				int x = i + go[0][k] , y = j + go[1][k];
				if(0 < x && x <= n && 0 < y && y <= n && mp[x][y])
					add(Get_Id(i , j) , Get_Id(x , y));
			}
}
inline bool find(int x){
	for(int i = h[x];i;i = e[i].next){
		int y = e[i].to;
		if(!vis[y]){
			vis[y] = 1;
			if(!col[y] || find(col[y])){
				col[y] = x;
				return 1;
			}
		}
	}
	return 0;
}
int 小臧同学(){
	ios :: sync_with_stdio(0);
	cin.tie(0);
	Init();
	for(int i = 1;i <= n;++ i)
		for(int j = 1;j <= n;++ j)
			if(Get_Id(i , j) & 1 && mp[i][j]){
				memset(vis , 0 , sizeof vis);
				ans -= find(Get_Id(i , j));
			}
	cout << ans;
	return 0;
}
/*
 [ ] * [ ] * [ ]
  * [ ][ ][ ] *
 [ ][ ] # [ ][ ]
  * [ ][ ][ ] *
 [ ] * [ ] * [ ]
*/
2022/9/22 23:22
加载中...