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源码解析
在分布式系统中,应对高并发访问时,缓存.限流.降级是保护系统正常运行的常用方法.当请求量突发暴涨时,如果不加以限制访问,则可能导致整个系统崩溃,服务不可用.同时有一些业务场景,比如短信验证码,或者其它 ...
随机推荐
- 比特币中P2SH(pay-to-script-hash)多重签名的锁定脚本和解锁脚本
P2SH(pay-to-script-hash)多重签名的脚本 P2SH是多重签名的一种应用形式.在P2SH的交易中,多了一个Redeem Script的概念,称为赎回脚本.当向P2SH脚本的地址转账 ...
- IOS 控制器的数据传递 (顺传 and 逆传)
● 控制器之间的数据传递主要有2种情况:顺传和逆传 ➢ 顺传 ● 控制器的跳转方向: A ->C ● 数据的传递方向 : A -> C ● 数据的传递方式 : 在A的prepareFo ...
- js转换时间戳成日期格式
<script> function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().rep ...
- AngularJS 应用
AngularJS模块(Module)定义了AngularJS的应用. AngularJS控制器(Controller)用于控制AngularJS应用. ng-app指令定义了应用,ng-contro ...
- C# 运用FileInfo类创建、删除文件
通过FileInfo类,我们可以方便地创建出文件,并可以访问文件的属性同时还可以对文件进行打开文件.关闭文件.读写文件等基本的操作.下面的代码显示了如何创建一个文本文件并且去访问其创建时间.文件的绝对 ...
- IPV6验证正则表达式
验证ipv6的正则表达式: 例:fe80::ec61:c1d1:9827:82be%13 \s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9 ...
- React Native 初探
推荐文章 React Native 简介:用 JavaScript 搭建 iOS 应用 (1) React Native 简介:用 JavaScript 搭建 iOS 应用 (2) React Nat ...
- Python 一行代码输出心形图案
Python3 >>> print('\n'.join([''.join([('Love'[(x-y)%4]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0. ...
- popen和pclose详解及实例
popen函数是标准c提供的一个管道创建函数,其内部操作主 要是创建一个管道,调用fork创建子进程,关闭不需用的文件描述符,调用exec函数族执行popen的第一个参数.然后等到关闭. 也就是说我们 ...
- 16.2--Jenkins+Maven+Gitlab+Tomcat 自动化构建打包、部署
分类: Linux服务篇,Linux架构篇 一.环境需求 本帖针对的是Linux环境,Windows或其他系统也可借鉴.具体只讲述Jenkins配置以及整个流程的实现. 1.JDK(或JRE)及J ...