hdu 4183 EK最大流算法
Pahom on Water
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 678 Accepted Submission(s): 312
on Water is an interactive computer game inspired by a short story of
Leo Tolstoy about a poor man who, in his lust for land, forfeits
everything. The game's starting screen displays a number of circular
pads painted with colours from the visible light spectrum. More than one
pad may be painted with the same colour (defined by a certain
frequency) except for the two colours red and violet. The display
contains only one red pad (the lowest frequency of 400 THz) and one
violet pad (the highest frequency of 789 THz). A pad may intersect, or
even contain another pad with a different colour but never merely touch
its boundary. The display also shows a figure representing Pahom
standing on the red pad.
The game's objective is to walk the figure
of Pahom from the red pad to the violet pad and return back to the red
pad. The walk must observe the following rules:
1.If pad α and pad β
have a common intersection and the frequency of the colour of pad α is
strictly smaller than the frequency of the colour of pad β, then Pahom
figure can walk from α to β during the walk from the red pad to the
violet pad
2. If pad α and pad β have a common intersection and the
frequency of the colour of pad α is strictly greater than the frequency
of the colour of pad β, then Pahom figure can walk from α to β during
the walk from the violet pad to the red pad
3. A coloured pad, with the exception of the red pad, disappears from display when the Pahom figure walks away from it.
The
developer of the game has programmed all the whizzbang features of the
game. All that is left is to ensure that Pahom has a chance to succeed
in each instance of the game (that is, there is at least one valid walk
from the red pad to the violet pad and then back again to the red pad.)
Your task is to write a program to check whether at least one valid path
exists in each instance of the game.
input starts with an integer K (1 <= K <= 50) indicating the
number of scenarios on a line by itself. The description for each
scenario starts with an integer N (2 <= N <= 300) indicating the
number of pads, on a line by itself, followed by N lines that describe
the colors, locations and sizes of the N pads. Each line contains the
frequency, followed by the x- and y-coordinates of the pad's center and
then the radius. The frequency is given as a real value with no more
than three decimal places. The coordinates and radius are given, in
meters, as integers. All values are separated by a single space. All
integer values are in the range of -10,000 to 10,000 inclusive. In each
scenario, all frequencies are in the range of 400.0 to 789.0 inclusive.
Exactly one pad will have a frequency of “400.0” and exactly one pad
will have a frequency of “789.0”.
2
400.0 0 0 4
789.0 7 0 2
4
400.0 0 0 4
789.0 7 0 2
500.35 5 0 2
500.32 5 0 3
Game is VALID
这题题目意思很难看懂。。我看了好长时间也没看懂。。最终是从网上找的翻译。。我就在这翻译一下吧。
意思大约是:有多个点,每个点给出坐标与半径,加入两个点相交,就可以从这两个点走。题目要求先从起点到终点,再从终点回到起点。从起点到终点的过 程中,只能从频率小的走到频率大的点(前提是两点相交),从终点到起点的过程中,只能从频率大的走到频率小的。在走的过程中,除了起点与终点,别的只要走 过就会消失,就是说只能走一次。问可不可以从起点到终点又回到起点。
初一看没什么思路,后来一想,无非就是从起点到终点走两次,均是从小到大,而且中间经过的点不重复即可。然后建图就很简单了。为了保证每个点只走一 次,可以把权值设为1,这样每一步最多只能走一次。然后看最大流是否大于等于2即可。还有一点需要注意的是,如果可以直接从起点到终点的话,就不用判断 了,肯定可以满足要求。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int inf=0x7fffffff;
int edge[][];//邻接矩阵
int dis[];//距源点距离,分层图
int start,end;
int m,n;//N:点数;M,边数
struct node{
double s;
int x,y,r;
}que[];
bool con(int i,int j){
if(((que[i].x-que[j].x)*(que[i].x-que[j].x)+(que[i].y-que[j].y)*(que[i].y-que[j].y))<(que[i].r+que[j].r)*(que[i].r+que[j].r))
return true;
else
return false;
} int maxflow, pre[];
void Edmonds_Karp(int start, int end, int m){
while()
{
queue<int>p;
int minflow = inf;
p.push(start);
memset(pre, , sizeof(pre));
while(!p.empty()){
int u = p.front();
p.pop();
if(u == end)
break;
for(int i = ;i <= m;i++)
if(edge[u][i] > &&pre[i] == ){
pre[i] = u;
p.push(i);
}
}
if(pre[end] == )
break;
for(int i = end;i != start;i = pre[i])
minflow = min(minflow, edge[pre[i]][i]);
for(int i = end;i != start;i = pre[i]) {
edge[pre[i]][i] -= minflow;
edge[i][pre[i]] += minflow;
}
maxflow+=minflow;
}
}
int main(){ int t;
scanf("%d",&t);
while(t--){
memset(que,,sizeof(que));
memset(edge,,sizeof(edge));
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lf%d%d%d",&que[i].s,&que[i].x,&que[i].y,&que[i].r);
} for(int i=;i<=n;i++){
if(que[i].s==400.0){
start=i;
}
if(que[i].s==789.0){
end=i;
} } for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
if(con(i,j)){
if(que[i].s>que[j].s)
edge[j][i]=;
else if(que[j].s>que[i].s)
edge[i][j]=;
}
}
}
maxflow = ;
Edmonds_Karp(start, end, n);
if(maxflow>=)
printf("Game is VALID\n");
else
printf("Game is NOT VALID\n");
}
return ;
}
hdu 4183 EK最大流算法的更多相关文章
- 最大流EK和Dinic算法
最大流EK和Dinic算法 EK算法 最朴素的求最大流的算法. 做法:不停的寻找增广路,直到找不到为止 代码如下: @Frosero #include <cstdio> #include ...
- 最大流算法之ISAP
序: 在之前的博文中,我解释了关于最大流的EK与Dinic算法,以及它们的STL/非STL的实现(其实没什么区别).本次讲解的是ISAP算法.'I',指 inproved,也就是说ISAP其实是SAP ...
- 最大流算法-ISAP
引入 最大流算法分为两类,一种是增广路算法,一种是预留推进算法.增广路算法包括时间复杂度\(O(nm^2)\)的EK算法,上界为\(O(n^2m)\)的Dinic算法,以及一些其他的算法.EK算法直接 ...
- Ford-Fulkerson 最大流算法
流网络(Flow Networks)指的是一个有向图 G = (V, E),其中每条边 (u, v) ∈ E 均有一非负容量 c(u, v) ≥ 0.如果 (u, v) ∉ E 则可以规定 c(u, ...
- 算法9-5:最大流算法的Java代码
残留网络 在介绍最大流算法之前先介绍一下什么是残留网络.残余网络的概念有点类似于集合中的补集概念. 下图是残余网络的样例. 上面的网络是原始网络.以下的网络是计算出的残留网络.残留网络的作用就是用来描 ...
- 海量数据挖掘MMDS week3:流算法Stream Algorithms
http://blog.csdn.net/pipisorry/article/details/49183379 海量数据挖掘Mining Massive Datasets(MMDs) -Jure Le ...
- 基于.net的分布式系统限流组件(限流算法:令牌算法和漏斗算法)
转载链接:https://www.cnblogs.com/vveiliang/p/9049393.html 1.令牌桶算法 令牌桶算法是比较常见的限流算法之一,大概描述如下: 1).所有的请求在处理之 ...
- hdu 1269 迷宫城堡(Targin算法)
---恢复内容开始--- 迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 常用限流算法与Guava RateLimiter源码解析
在分布式系统中,应对高并发访问时,缓存.限流.降级是保护系统正常运行的常用方法.当请求量突发暴涨时,如果不加以限制访问,则可能导致整个系统崩溃,服务不可用.同时有一些业务场景,比如短信验证码,或者其它 ...
随机推荐
- hdu-2112 HDU Today---dijkstra+标号
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2112. 题目大意: 求起点到终点的最短路 解题思路: 对地名进行编号即可 然后直接dijkstra算 ...
- iOS 制作表格 (数据源控制行,列数)
记得去年面试的过程中,有一个面试官问我怎么制作表格.由于之前也没有做过,当时有点懵逼,今天想起来了,就用tableview制作了一个,望不要有人像我一样掉坑了, 直接上代码: // // ViewCo ...
- 自动生成 WebApi 在线说明文档。
1.使用Swashbuckle实现 Swashbuckle 是.NET类库,可以将WebAPI所有开放的控制器方法生成对应SwaggerUI的JSON配置.再通过SwaggerUI 显示出来.类库中已 ...
- js当中mouseover和mouseout多次触发(非冒泡)
JS当中,mouseover和mouseout多次触发事件,不光是冒泡会产生,就是不冒泡,在一定条件下 ,也会产生多次触发事件: 例如下面的结构的情况下,我在class="ceng_up f ...
- Java传值分析
public class Example{String str=new String("good");char[] ch={'a','b','c'};public static v ...
- cf550D. Regular Bridge(构造)
题意 给出一个$k$,构造一个无向图,使得每个点的度数为$k$,且存在一个桥 Sol 神仙题 一篇写的非常好的博客:http://www.cnblogs.com/mangoyang/p/9302269 ...
- Linux监控二之cacti简单安装部署
目录 cacti简单部署 1 环境依赖包部署 1 1. cacti中文版0.8e搭建 2 2. cacti安装向导 url:http://192.168.200.243/ ...
- vue 组件的书写
简单的来说是 vue组件最核心的就是props和自定义函数,来实现组件的开发 最简单的一个组件 子组件如下: <template> <div class="bgClass& ...
- linux 的安装
3linux 软件安装 3.1 vm ware 软件安装 双击VMware-workstation-full-10.0.2-1744117.1398244508.exe 单击下一步 单击下一步 选择典 ...
- hive的常用HQL语句
1.过滤条件 where .limit. distinct. between and . null. is not nullselect * from emp where sal > 3000; ...