RT,一般思路,WA#3#5#6#8,代码如下
/*
By Nero Claudius Caeser Augustus Germanicus,
Imeratorum Romanorum.
*/
#include <bits/stdc++.h>
using namespace std;
namespace StandardIO{
template<typename T>void read(T &x){
x=0;T f=1;char c=getchar();
for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=-1;
for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
x*=f;
}
template<typename T>void write(T x){
if(x<0) putchar('-'),x*=-1;
if(x>=10) write(x/10);
putchar(x%10+'0');
}
} using namespace StandardIO;
namespace Project{
const int N=2000+10;
const int dis[8][2]={{3,1},{3,-1},{1,3},{1,-3},{-3,1},{-3,-1},{-1,3},{-1,-3}};
int n,m,K,ans,S,T;
int cnt=1;
int head[N*N];
struct node{
int to,next,val;
} edge[N*N];
int dep[N*N];
queue<int> q;
int block[N][N];
inline void _add(int a,int b,int c){
edge[++cnt].to=b,edge[cnt].val=c,edge[cnt].next=head[a],head[a]=cnt;
}
inline void add(int a,int b,int c){
_add(a,b,c),_add(b,a,0);
}
bool bfs(){
memset(dep,0,sizeof(dep));
dep[S]=1,q.push(S);
while(q.size()){
int now=q.front();q.pop();
for(int i=head[now]; i; i=edge[i].next){
int to=edge[i].to;
if(edge[i].val&&!dep[to]){
dep[to]=dep[now]+1;
q.push(to);
}
}
}
return dep[T];
}
int dfs(int now,int f){
if(now==T) return f;
int used=0;
for(int i=head[now],w; i; i=edge[i].next){
int to=edge[i].to;
if(edge[i].val&&dep[to]==dep[now]+1){
w=dfs(to,min(f-used,edge[i].val));
edge[i].val-=w,edge[i^1].val+=w,used+=w;
if(used==f) return f;
}
}
if(!used) dep[now]=-1;
return used;
}
void dinic(){
while(bfs()) ans+=dfs(S,2147400000);
}
void MAIN(){
read(n),read(m),read(K),S=0,T=n*m+1;
for(int i=1,x,y; i<=K; ++i){
read(x),read(y);
block[x][y]=1;
}
for(int i=1; i<=n; ++i){
for(int j=1,cur; j<=m; ++j){
cur=j+(i-1)*m;
if(i&1){
add(S,cur,1);
}else{
add(cur,T,1);
}
}
}
for(int i=1; i<=n; ++i){
for(int j=1,cur; j<=m; ++j){
if(block[i][j]) continue;
if(i&1){
cur=j+(i-1)*m;
for(int k=0,x,y; k<8; ++k){
x=i+dis[k][0],y=j+dis[k][1];
if(x<1||x>n||y<1||y>m||block[x][y]) continue;
add(cur,y+(x-1)*m,1);
}
}
}
}
dinic();
write(n*m-K-ans);
}
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
Project::MAIN();
}
谢谢!