标签:ati man sizeof ref log nal 容量 file port
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 715 | Accepted: 251 |
Description
Input
Output
Sample Input
3 3 2 0 1 1 0 2 0 2 2 2 0 2 2 2 0 3 4 0 2 2 0 4 0 1 1 1 0 1 1 1 0 4 0 3 3 1 1 3 3 0 0 0 0 2 0 0 1 0 0 1 0 0 2 0 0 0
Sample Output
1 2 3 1 2 2 4
Source
// // main.cpp // poj1336 // // Created by Candy on 26/11/2016. // Copyright © 2016 Candy. All rights reserved. // #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N=1005,INF=1e9; int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } int T,n,num,sum,win[N],los[N],s,t,c[N][N]; struct edge{ int v,ne,c,f; }e[N<<1]; int cnt,h[N]; inline void ins(int u,int v,int c){//printf("ins %d %d %d\n",u,v,c); cnt++; e[cnt].v=v;e[cnt].c=c;e[cnt].f=0;e[cnt].ne=h[u];h[u]=cnt; cnt++; e[cnt].v=u;e[cnt].c=0;e[cnt].f=0;e[cnt].ne=h[v];h[v]=cnt; } int tot; bool build(int x){//printf("build %d\n",tot); cnt=0; memset(h,0,sizeof(h)); for(int i=1;i<=n;i++) if(i!=x){ for(int j=i+1;j<=n;j++) if(j!=x){ int id=(i-1)*n+j; ins(s,id,c[i][j]); ins(id,num+i,INF); ins(id,num+j,INF); } ins(num+i,t,tot-win[i]); if(tot-win[i]<0) return false; } return true; } int cur[N]; int vis[N],d[N],q[N],head,tail; bool bfs(){ memset(vis,0,sizeof(vis)); memset(d,0,sizeof(d)); head=tail=1; q[tail++]=s;d[s]=0;vis[s]=1; while(head!=tail){ int u=q[head++]; for(int i=h[u];i;i=e[i].ne){ int v=e[i].v; if(!vis[v]&&e[i].c>e[i].f){ vis[v]=1;d[v]=d[u]+1; q[tail++]=v; if(v==t) return 1; } } } return 0; } int dfs(int u,int a){ if(u==t||a==0) return a; int flow=0,f; for(int &i=cur[u];i;i=e[i].ne){ int v=e[i].v; if(d[v]==d[u]+1&&(f=dfs(v,min(a,e[i].c-e[i].f)))>0){ flow+=f; e[i].f+=f; e[((i-1)^1)+1].f-=f; a-=f; if(a==0) break; } } return flow; } int dinic(){ int flow=0; while(bfs()){ for(int i=s;i<=t;i++) cur[i]=h[i]; flow+=dfs(s,INF); } return flow; } int main(int argc, const char * argv[]) { T=read(); while(T--){ n=read();s=0;t=n*n+n+1;num=n*n;sum=0; for(int i=1;i<=n;i++) win[i]=read(),los[i]=read(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) c[i][j]=read(),sum+=j>i?c[i][j]:0; for(int i=1;i<=n;i++){//printf("sol %d\n",i); tot=win[i]; for(int j=1;j<=n;j++) tot+=c[i][j]; if(!build(i)) continue; int tmp=dinic();//printf("dinic %d sum %d %d\n",tmp,sum,sum-tot+win[i]); if(tmp==sum-tot+win[i]) printf("%d ",i); } puts(""); } return 0; }
POJ1336 The K-League[最大流 公平分配问题]
标签:ati man sizeof ref log nal 容量 file port
原文地址:http://www.cnblogs.com/candy99/p/6103922.html