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

Problem Description
Pahom
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
The
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”.
 
Output
The output for each scenario consists of a single line that contains: Game is VALID, or Game is NOT VALID
 
Sample Input
2
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
 
Sample Output
Game is NOT VALID
Game is VALID
 
Source

这题题目意思很难看懂。。我看了好长时间也没看懂。。最终是从网上找的翻译。。我就在这翻译一下吧。

意思大约是:有多个点,每个点给出坐标与半径,加入两个点相交,就可以从这两个点走。题目要求先从起点到终点,再从终点回到起点。从起点到终点的过 程中,只能从频率小的走到频率大的点(前提是两点相交),从终点到起点的过程中,只能从频率大的走到频率小的。在走的过程中,除了起点与终点,别的只要走 过就会消失,就是说只能走一次。问可不可以从起点到终点又回到起点。

初一看没什么思路,后来一想,无非就是从起点到终点走两次,均是从小到大,而且中间经过的点不重复即可。然后建图就很简单了。为了保证每个点只走一 次,可以把权值设为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最大流算法的更多相关文章

  1. 最大流EK和Dinic算法

    最大流EK和Dinic算法 EK算法 最朴素的求最大流的算法. 做法:不停的寻找增广路,直到找不到为止 代码如下: @Frosero #include <cstdio> #include ...

  2. 最大流算法之ISAP

    序: 在之前的博文中,我解释了关于最大流的EK与Dinic算法,以及它们的STL/非STL的实现(其实没什么区别).本次讲解的是ISAP算法.'I',指 inproved,也就是说ISAP其实是SAP ...

  3. 最大流算法-ISAP

    引入 最大流算法分为两类,一种是增广路算法,一种是预留推进算法.增广路算法包括时间复杂度\(O(nm^2)\)的EK算法,上界为\(O(n^2m)\)的Dinic算法,以及一些其他的算法.EK算法直接 ...

  4. Ford-Fulkerson 最大流算法

    流网络(Flow Networks)指的是一个有向图 G = (V, E),其中每条边 (u, v) ∈ E 均有一非负容量 c(u, v) ≥ 0.如果 (u, v) ∉ E 则可以规定 c(u, ...

  5. 算法9-5:最大流算法的Java代码

    残留网络 在介绍最大流算法之前先介绍一下什么是残留网络.残余网络的概念有点类似于集合中的补集概念. 下图是残余网络的样例. 上面的网络是原始网络.以下的网络是计算出的残留网络.残留网络的作用就是用来描 ...

  6. 海量数据挖掘MMDS week3:流算法Stream Algorithms

    http://blog.csdn.net/pipisorry/article/details/49183379 海量数据挖掘Mining Massive Datasets(MMDs) -Jure Le ...

  7. 基于.net的分布式系统限流组件(限流算法:令牌算法和漏斗算法)

    转载链接:https://www.cnblogs.com/vveiliang/p/9049393.html 1.令牌桶算法 令牌桶算法是比较常见的限流算法之一,大概描述如下: 1).所有的请求在处理之 ...

  8. hdu 1269 迷宫城堡(Targin算法)

    ---恢复内容开始--- 迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. 常用限流算法与Guava RateLimiter源码解析

    在分布式系统中,应对高并发访问时,缓存.限流.降级是保护系统正常运行的常用方法.当请求量突发暴涨时,如果不加以限制访问,则可能导致整个系统崩溃,服务不可用.同时有一些业务场景,比如短信验证码,或者其它 ...

随机推荐

  1. [Rodbourn's Blog]How to export Excel plots to a vector image (EPS, EMF, SVG, etc.)

    This is a bit of a workaround, but it's the only way I know of to export an Excel plot into a vector ...

  2. EF和linq语句查询条件不等于某个参数出现的问题

    where t.a!=字符串   这是错误的写法,正确为 where t.a!=字符串.trim() 其他类型变量需要保持实体类型和查询条件参数的类型是一致的,不然出现的语句可能会是 类似`Exten ...

  3. python_21_copy

    import copy person=['name',['saving',100]] #3种浅copy方式 p1=copy.copy(person) p2=person[:] p3=list(pers ...

  4. java基础面试题:请说出作用域public,private,protected,以及不写时的区别

    不写任何作用域(即访问权限)表示friendly public 公共,权限最大,作用域最大,在类内部.同一package.子孙类.其他package都可以访问 protected保护,在类内部.同一p ...

  5. 使用git stash命令保存和恢复进度

    使用git stash命令保存和恢复进度 git stash 保存当前工作进度,会把暂存区和工作区的改动保存起来.执行完这个命令后,在运行git status命令,就会发现当前是一个干净的工作区,没有 ...

  6. Angular2 Service获取json数据

    在Angular2框架下一般交互解析json是要用到Service的,其实除了Service还是很多的,今天先写个最简单的前后端数据交互 嗯~~ 首先我先在app包下直接创建Service 好了 这里 ...

  7. Spring+ ApplicationListener

    有时候 需要在容器初始化完成后,加载些 代码字典或不常变的信息  放入缓存之类的,这里使用spring 初始化bean,并实例化 1.创建一个ApplicationListener类 import o ...

  8. git 命令汇总

    本地库处理 git init 初始化仓库 git clone [地址] 下载项目 git status 查看当前暂存等状态 git add 添加暂存 cat .git/config 查看git配置 l ...

  9. Linux更改文件权限(二)

    更改文件权限(二)============================== (参考于千锋教育教学笔记) 命令umask [root@aminglinux ~]# umask 0022 [root@ ...

  10. 同时启动多个tomcat的配置信息

    同时启动多个tomcat的配置信息 下面把该配置文件中各端口的含义说明下. <Server port="8005" shutdown="SHUTDOWN" ...