Lamorak @ 2021-07-15 17:20:53
可能我的dinic和大佬们的有巨大不同
#include<bits/stdc++.h>
using namespace std;
const int N=7*1e6;
const int inf=1e9+90;
int n,m,head[N],tot,now[N],p[300][300],dis[N],s,t,ans;
int move[8][2]={{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
//now[]为当前弧优化
struct node{
int next,v,flow;
}ed[N];
inline int qwe(int i,int j){
return (i-1)*n+j;
}
inline void add(int x,int y,int z){
ed[++tot].next=head[x];
ed[tot].v=y;
ed[tot].flow=z;
head[x]=tot;
}
inline bool bfs(){
queue<int>q;
for(int i=0;i<=t+1;i++) dis[i]=inf;
q.push(s);
dis[s]=0;
now[s]=head[s];
while(!q.empty()){
int x=q.front();
q.pop();
for(int i=head[x];i!=-1;i=ed[i].next){
int v=ed[i].v;
int f=ed[i].flow;
if(f>0&&dis[v]==inf){
dis[v]=dis[x]+1;
now[v]=head[v];
q.push(v);
if(v==t) return 1;
}
}
}
return 0;
}
inline int dfs(int x,int sum){
if(x==t) return sum;
int res=0,k=0;
for(int i=now[x];i!=0&∑i=ed[i].next){
now[x]=i;//当前弧优化
int v=ed[i].v,f=ed[i].flow;
if(f>0&&dis[v]==dis[x]+1){
k=dfs(v,min(f,sum));
if(k==0) dis[v]=inf;//剪枝
ed[i].flow-=k;
ed[i^1].flow+=k;
res+=k;
sum-=k;
}
}
return res;
}
int main(){
scanf("%d%d",&n,&m);
memset(head,-1,sizeof(head));
s=0;
t=n*n+2;
tot=1;
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
p[x][y]=1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if((i+j)&1){
if(!p[i][j]){
add(s,qwe(i,j),1);
add(qwe(i,j),s,0);
}
}
else if(!p[i][j]){
add(qwe(i,j),t,1);
add(t,qwe(i,j),0);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(!(i+j)&1) continue;
for(int k=0;k<8;k++){
int x=i+move[k][0];
int y=j+move[k][1];
if(x<=0||x>n||y<=0||y>n||p[x][y]==1) continue;
add(qwe(i,j),qwe(x,y),inf);
add(qwe(x,y),qwe(i,j),0);
}
}
}
while(bfs()){
ans+=dfs(s,inf);
}
printf("%d",n*n-m-ans);
return 0;
}
目前状况37分
求助,谢谢
by stntn @ 2021-07-15 19:08:07
期待你的直播
by Lamorak @ 2021-07-15 20:08:14
@stntn 请不要做无意义的回复否则将遭到举报
by stntn @ 2021-07-15 20:14:50
if(!(i+j)&1) continue;
改为
if(!((i+j)&1)) continue;
记住我我是活雷锋做好事不留名
by stntn @ 2021-07-15 20:18:11
您不应该使用如此华而不实的位运算而忘记了%
by Lamorak @ 2021-07-15 20:24:51
@stntn
by Lamorak @ 2021-07-15 20:26:19
extra:最好别自称“活雷锋”
by stntn @ 2021-07-15 20:30:50
@UKE_ 1.非常无趣
2.我不想帮助别人
3.我语言平易近人
4.
by stntn @ 2021-07-15 20:31:55
extra:记住我我是活雷锋做好事不留名