poj 3498 March of the Penguins 点流量有限制的最大流
来源:互联网 发布:js将字符串分割成数组 编辑:程序博客网 时间:2024/05/18 02:19
题意:
给n块浮冰的坐标,每块浮冰上的企鹅数和能承受跳起的次数,求有哪些浮冰能让企鹅能到一起。
分析:
拆点将点流量的限制转化为边流量的限制,求最大流。
代码:
//poj 3498//sep9#include <iostream>#include <queue>#include <algorithm>#include <cmath>using namespace std;const int maxN=128;const int maxM=40;const int maxV=260;const int maxE=26000;struct Edge{int u,v,f,nxt;}e[maxE*2+10];queue<int> que;int src,sink;int g[maxV+10];int nume;bool vis[maxV+10];int dist[maxV+10];double x[maxN],y[maxN];int num[maxN],m[maxN];void addedge(int u,int v,int c){e[nume].u=u,e[nume].v=v;e[nume].f=c;e[nume].nxt=g[u];g[u]=nume++;e[nume].u=v;e[nume].v=u;e[nume].f=0;e[nume].nxt=g[v];g[v]=nume++;}void init(){memset(g,0,sizeof(g));nume=2;}int bfs(){while(!que.empty()) que.pop();memset(dist,0,sizeof(dist));memset(vis,0,sizeof(vis));vis[src]=true;que.push(src);while(!que.empty()){int u=que.front();que.pop();for(int i=g[u];i;i=e[i].nxt)if(e[i].f&&!vis[e[i].v]){que.push(e[i].v);dist[e[i].v]=dist[u]+1;vis[e[i].v]=true; if(e[i].v==sink)return 1;}}return 0;}int dfs(int u,int delta){if(u==sink)return delta;int ret=0;for(int i=g[u];ret<delta&&i;i=e[i].nxt)if(e[i].f&&dist[e[i].v]==dist[u]+1){int dd=dfs(e[i].v,min(e[i].f,delta-ret));if(dd>0){e[i].f-=dd;e[i^1].f+=dd;ret+=dd;}elsedist[e[i].v]=-1;}return ret;}int dinic(){int ret=0;while(bfs()==1)ret+=dfs(src,INT_MAX);return ret;}void solve(){int i,j,t,n,sum;double D;scanf("%d%lf",&n,&D);sum=0,src=2*n;int ok=0;for(i=0;i<n;++i){scanf("%lf%lf%d%d",&x[i],&y[i],&num[i],&m[i]);sum+=num[i];}for(t=0;t<n;++t){init();for(i=0;i<n;++i){addedge(src,i,num[i]);addedge(i,i+n,m[i]);}for(i=0;i<n;++i)for(j=0;j<n;++j)if(i!=j){double L=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));if(L<D||fabs(L-D)<1e-6){addedge(i+n,j,INT_MAX);}}sink=t;if(dinic()==sum){printf("%d ",t);ok=1;}}if(!ok)printf("-1");printf("\n");}int main(){int cases;scanf("%d",&cases);while(cases--)solve();return 0;}
0 0
- poj 3498 March of the Penguins 点流量有限制的最大流
- poj 3498 March of the Penguins(满足点容量限制的网络流)
- POJ 3498 March of the Penguins(枚举+最大流)
- POJ 3498 March of the Penguins(枚举+最大流)
- POJ 3498 March of the Penguins(枚举+最大流)
- POJ 3498 - March of the Penguins 拆点构图最大流
- POJ 3498 March of the Penguins
- POJ 3498 March of the Penguins
- poj 3498(March of the Penguins)
- POJ-3498-March of the Penguins
- POJ 3498 March of the Penguins
- POJ 3498March of the Penguins
- POJ 3498 && HDU 2334 March of the Penguins(最大流-Dinic)
- POJ 3498 —— March of the Penguins (枚举+最大流)
- POJ March of the Penguins
- La (NWERC2007 Problem B )- March of the Penguins(最大流 拆点)
- uva 12125 - March of the Penguins(最大流)
- UVA 12125 - March of the Penguins(最大流)
- android inflater
- http apache服务器配置(域名+转发端口)
- 解决php session验证码不现实的问题
- 南阳 一道水题
- Problem C 比大小
- poj 3498 March of the Penguins 点流量有限制的最大流
- Ubuntu14.04下安装Android Studio 1.0
- 求余数
- 关于Java的泛型方法
- JDBC驱动mysql的中文乱码解决方案
- footer jquery不错的底部切换。 亮点在于 , script 代码
- Android Fragment使用中遇到的几点问题
- C杂碎
- HDU ACM 1061 Rightmost Digit