hdu 4183 Pahom on Water 网络流
来源:互联网 发布:淘宝客推广在哪里设置 编辑:程序博客网 时间:2024/06/09 19:41
题意 二维空间上有一些点,每个点有一个半径r和频率f,要从某一个点S走到另一个点T,然后再从T回到S。从S到T时,如果两个点表示的圆相交并且第一个点小于第二个点的频率的,那么能从第一个点到第二个点,从T到S时,第一个点的频率要大于第二个点的频率。除了S和T,每个点走后就会消失,问是否存在一种走法。
相当于从源点向汇点走两次,每个点走完后消失,所以拆点,求最大流,如果最大流大于等于2或源点与汇点相交则可以。
#include <cstdio>#include <cstring>#include <vector>#include <queue>using namespace std;#define maxn 1000#define INF 100000struct Edge{ int from, to, cap, flow;};struct Node{ double f; int x,y,r;}nod[maxn];int n, s, t;vector<Edge> edges; // 边数的两倍vector<int> G[maxn]; // 邻接表,G[i][j]表示结点i的第j条边在e数组中的序号bool vis[maxn]; // BFS使用int d[maxn]; // 从起点到i的距离int cur[maxn]; // 当前弧指针int min(int a,int b){ if(a<b) return a; else return b;}void AddEdge(int from, int to, int cap){ int len; Edge temp; temp.from=from;temp.to=to;temp.cap=cap;temp.flow=0; edges.push_back(temp); temp.from=to;temp.to=from;temp.cap=0;temp.flow=0; edges.push_back(temp); len = edges.size(); G[from].push_back(len-2); G[to].push_back(len-1);}bool BFS(){ memset(vis, 0, sizeof(vis)); queue<int> Q; Q.push(s); vis[s] = 1; d[s] = 0; while(!Q.empty()) { int x = Q.front(); Q.pop(); for(int i = 0; i < G[x].size(); i++) { Edge& e = edges[G[x][i]]; if(!vis[e.to] && e.cap > e.flow) { vis[e.to] = 1; d[e.to] = d[x] + 1; Q.push(e.to); } } } return vis[t];}int DFS(int x, int a){ if(x == t || a == 0) return a; int flow = 0, f; for(int& i = cur[x]; i < G[x].size(); i++) { Edge& e = edges[G[x][i]]; if(d[x] + 1 == d[e.to] && (f = DFS(e.to, min(a, e.cap-e.flow))) > 0) { e.flow += f; edges[G[x][i]^1].flow -= f; flow += f; a -= f; if(a == 0) break; } } return flow;}int Maxflow(){ int flow = 0; while(BFS()) { memset(cur, 0, sizeof(cur)); flow += DFS(s, INF); } return flow;}int dist(int i,int j){ return (nod[i].x-nod[j].x)*(nod[i].x-nod[j].x)+(nod[i].y-nod[j].y)*(nod[i].y-nod[j].y);}int main(){ int K; scanf("%d",&K); int i,j; while(K--) { scanf("%d",&n); for(i=0;i<=2*n+10;i++) G[i].clear(); for(i=1;i<=n;i++) { scanf("%lf%d%d%d",&nod[i].f,&nod[i].x,&nod[i].y,&nod[i].r); if(nod[i].f==400.0) s=i+n; if(nod[i].f==789.0) t=i; } if(dist(s-n,t)<=((nod[s-n].r+nod[t].r)*(nod[s-n].r+nod[t].r))) { printf("Game is VALID\n"); return 0; } for(i=1;i<=n;i++) AddEdge(i,i+n,1); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(i==j) continue; if(nod[i].f<nod[j].f&&dist(i,j)<=((nod[i].r+nod[j].r)*(nod[i].r+nod[j].r))) AddEdge(i+n,j,INF); } int ans=Maxflow(); if(ans>=2) printf("Game is VALID\n"); else printf("Game is NOT VALID\n"); } return 0;}
0 0
- hdu 4183 Pahom on Water 网络流
- 【网络流】 HDU 4183 Pahom on Water 拆点
- hdu 4183 Pahom on Water(最大流)
- hdu 4183 Pahom on Water 最大流
- HDU 4183 Pahom on Water 最大流
- hdu 4183 Pahom on Water (最大流)
- HDU 4183 Pahom on Water
- Pahom on Water HDU
- HDU 4183Pahom on Water(网络流之最大流)
- HDU 4183 Pahom on Water 来回走不重复点的网络流
- HDU 4183 Pahom on Water 来回走不重复点的网络流
- hdu 4183 Pahom on Water 最大流 isap
- HDU 4183 Pahom on Water(最大流SAP)
- HDU -- 4183 Pahom on Water(最大流)
- HDU 4183--Pahom on Water【最大流dinic】
- HDU 4183 Pahom on Water (拆点最大流)
- hdu 4183 Pahom on Water(最大流)
- HDU 4183 Pahom on Water(点双连通分量)
- MySQLdb For Python On Windows
- 题目1032:ZOJ
- GE SmallWorld开发(004加载SOMs)
- soaplib v2.0.0 HelloWorld
- JAVA中int、String的类型转换
- hdu 4183 Pahom on Water 网络流
- FROM子句
- Bochs使用[练习自己动手写操作系统]
- C中字符串处理
- [ACM] hdu 2602 Bone Collector(01背包)
- 【转】通过Python脚本自动发布ArcGIS服务
- Hadoop2.2.0伪分布式安装及测试笔记
- UNIX高级环境编程读书笔记(chapter14)
- strmiids.lib 导致的链接错误