partychicken @ 2018-08-04 20:51:57
81分,两个大数据过不去。。。
貌似是死循环了,在本机跑了40min没出答案
#include<bits/stdc++.h>
using namespace std;
const int N=40010;
const int inf=0x3f3f3f3f;
const int dx[]={1,2,2,1,-1,-2,-2,-1};
const int dy[]={2,1,-1,-2,-2,-1,1,2};
struct Edge
{
int to,nxt,val;
Edge():nxt(-1){}
}e[N<<4];
int head[N],cnt(-1);
void addedge(int u,int v,int val)
{
e[++cnt].to=v;
e[cnt].val=val;
e[cnt].nxt=head[u];
head[u]=cnt;
}
void insedge(int u,int v,int val)
{
addedge(u,v,val);
addedge(v,u,0);
}
int s,t;
queue<int>q;
int dpth[N];
bool bfs()
{
while(!q.empty())
{
q.pop();
}
memset(dpth,0,sizeof(dpth));
dpth[s]=1;
q.push(s);
while(!q.empty())
{
int now=q.front();
q.pop();
for(int i=head[now];~i;i=e[i].nxt)
{
if(!dpth[e[i].to]&&e[i].val)
{
dpth[e[i].to]=dpth[now]+1;
q.push(e[i].to);
}
}
}
return (bool)dpth[t];
}
int dfs(int now,int fl)
{
if(now==t||fl==0)
{
return fl;
}
int di=0;
for(int i=head[now];~i;i=e[i].nxt)
{
int vs=e[i].to;
if(dpth[vs]==dpth[now]+1)
{
int tmp=dfs(vs,min(fl-di,e[i].val));
//if(!tmp)dpth[vs]=0;
e[i].val-=tmp;
e[i^1].val+=tmp;
di+=tmp;
}
}
return di;
}
int dinic()
{
int res=0;
while(bfs())
{
res+=dfs(s,inf);
}
return res;
}
int mp[210][210];
int n,m;
int geid(int i,int j)
{
return (i-1)*n+j;
}
int main()
{
memset(head,-1,sizeof(head));
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
mp[x][y]=1;
}
s=n*n+100;
t=n*n+200;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(mp[i][j])
{
continue;
}
else
{
int u=geid(i,j);
if((i+j)&1)
{
insedge(s,u,1);
}
else
{
insedge(u,t,1);
continue;
}
for(int p=0;p<8;p++)
{
int nowx=i+dx[p];
int nowy=j+dy[p];
if(nowx>0&&nowy>0&&nowx<=n&&nowy<=n&&(!mp[nowx][nowy]))
{
int v=geid(nowx,nowy);
insedge(u,v,inf);
}
}
}
}
}
cout<<n*n-m-dinic()<<endl;
}
by 陈独秀先生_ @ 2018-08-04 21:24:32
您好,请问您为什么要强调您刚学C++呢
by 天依赛高! @ 2018-08-13 21:30:38
别人应该是P转C啊喂
怎么玩起梗来了...
by Xeonacid @ 2018-08-20 12:56:50
您好,请问您为什么要强调您刚学 C++ 呢???