bzoj1312 Neerc2006 Hard Life(01规划+最小割)

01规划，我们二分答案mid，如果$E/V>mid$$E/V>mid$，那么有$E-V\ast mid>0$$E-V*mid>0$

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 1111
#define eps 1e-8
inline char gc(){
static char buf[1<<16],*S,*T;
return *S++;
}
int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
return x*f;
}
int n,m,h[N],num=1,cur[N],lev[N],T=1110;
struct edge{
int to,next;double val;
}data[7000];
inline void add(int x,int y,double val){
data[++num].to=y;data[num].next=h[x];h[x]=num;data[num].val=val;
data[++num].to=x;data[num].next=h[y];h[y]=num;data[num].val=0;
}
inline bool bfs(){
queue<int>q;memset(lev,0,sizeof(lev));
q.push(0);lev[0]=1;
while(!q.empty()){
int x=q.front();q.pop();
for(int i=h[x];i;i=data[i].next){
int y=data[i].to;if(lev[y]||data[i].val<=eps) continue;
lev[y]=lev[x]+1;if(y==T) return 1;q.push(y);
}
}return 0;
}
inline double dinic(int x,double low){
if(x==T) return low;double tmp=low;
for(int &i=cur[x];i;i=data[i].next){
int y=data[i].to;if(lev[y]!=lev[x]+1||data[i].val<=eps) continue;
double res=dinic(y,min(tmp,data[i].val));
if(res<=eps) lev[y]=0;else data[i].val-=res,data[i^1].val+=res,tmp-=res;
if(tmp<=eps) return low;
}return low-tmp;
}
inline bool jud(double mid){
num=1;double res=0;
for(int i=1;i<=n;++i) data[++num].val=mid,data[++num].val=0;
for(int i=1;i<=m;++i) data[++num].val=1,data[++num].val=0,
data[++num].val=1,data[++num].val=0,data[++num].val=1,data[++num].val=0;
while(bfs()){
memcpy(cur,h,sizeof(h));res+=dinic(0,inf);}
return m-res>eps;
}
int main(){
//  freopen("a.in","r",stdin);
for(int i=1;i<=m;++i){
}double l=0,r=m;
while(r-l>=1.0/n/n){
double mid=(r+l)/2;
if(jud(mid)) l=mid;
else r=mid;
}jud(l);int ans=0;bfs();
for(int i=1;i<=n;++i) if(lev[i]) ++ans;
printf("%d\n",ans);
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120