Pahom on Water

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 885    Accepted Submission(s): 409

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
 
题意:平面上有一些点,他们有着各自的坐标,频率,半径 ,可以从一个点到另一个点的条件是两点的距离小于半径之和,现在我们要从频率最小的点走到频率最大的点,规则是每次只能从频率小的走到频率大的,然后又要走回来,规则刚好是相反的,问是否存在这样一种方案使得上述条件成立。
题解:将第二个规则与第一个规则合并,问题就变成了是否存在两条不同的路使得起点(f最低)能够到达终点(f最高)先对所有点按照频率排序,然后构图,频率低的向频率高的连一条容量为1的边,这样的话就能够保证每条边最多走一次,然后求一次最大流,如果最大流大于等于2就存在这样的两条路。
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
const int N = ;
const int INF = ;
int cap[N][N];
int flow[N];
int pre[N];
int n;
struct Node{
int x,y,r;
double f;
}node[N];
double dis(Node a,Node b){
return sqrt(1.0*((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
}
int bfs(int src,int des){
queue<int> q;
for(int i=;i<=des;i++){
pre[i]=-;
}
pre[src]=;
flow[src]=INF;
q.push(src);
while(!q.empty()){
int u = q.front();
q.pop();
if(u==des) break;
for(int i=;i<=des;i++){
if(i!=src&&cap[u][i]>&&pre[i]==-){
pre[i] = u;
flow[i] = min(cap[u][i],flow[u]);
q.push(i);
}
}
}
if(pre[des]==-) return -;
return flow[des];
} int max_flow(int src,int des){
int ans = ,increaseRoad;
while((increaseRoad=bfs(src,des))!=-){
int k = des;
while(k!=src){
cap[pre[k]][k]-=increaseRoad;
cap[k][pre[k]]+=increaseRoad;
k = pre[k];
}
ans+=increaseRoad;
}
return ans;
}
int cmp(Node a,Node b){
return a.f<b.f;
}
void build(){
scanf("%d",&n);
memset(cap,,sizeof(cap));
for(int i=;i<=n;i++){
scanf("%lf%d%d%d",&node[i].f,&node[i].x,&node[i].y,&node[i].r);
}
sort(node+,node+n+,cmp);
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
if(i!=j&&dis(node[i],node[j])<=(node[i].r+node[j].r)){
cap[i][j]=;
}
}
}
}
int main(){
int tcase;
scanf("%d",&tcase);
while(tcase--){
build();
int t = max_flow(,n);
if(t>=) printf("Game is VALID\n");
else printf("Game is NOT VALID\n");
}
}

hdu 4183(网络流)的更多相关文章

  1. 【解题报告】 Leapin' Lizards HDU 2732 网络流

    [解题报告] Leapin' Lizards HDU 2732 网络流 题外话 在正式讲这个题目之前我想先说几件事 1. 如果大家要做网络流的题目,我在网上看到一个家伙,他那里列出了一堆网络流的题目, ...

  2. HDU 1083 网络流之二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...

  3. HDU 4888 (网络流)

    Poroblem Redraw Beautiful Drawings (HDU4888) 题目大意 一个n行m列的矩形,只能填0~k的数字. 给定各行各列的数字和,判定有无合法的方案数.一解给出方案, ...

  4. hdu 4280 网络流

    裸的网络流,递归的dinic会爆栈,在第一行加一句就行了 #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...

  5. HDU 4292Food(网络流的最大流量)

    职务地址:HDU 4292 水题. 因为每一个人仅仅能有1份,所以须要拆点限制流量.建图方法为,建一源点与汇点.将食物与源点相连,权值为食物额数量,将饮料与汇点相连,权值为饮料数量..然后将人进行拆点 ...

  6. Food HDU - 4292 网络流 拆点建图

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...

  7. hdu 1565&hdu 1569(网络流--最小点权值覆盖)

    方格取数(1) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. HDU - 2828 网络流

    题目大意 有n个灯,m个开关,由于线路乱接导致可能有多个开关对应一个灯(并联),有的灯在开关开的时候亮 有的灯在开关关的时候亮,[每个开关最多对应两盏灯],试找出一种开关的ON,OFF状态,使得所有灯 ...

  9. HDU 6634 网络流最小割模型 启发式合并

    如果我们先手拿完所有苹果再去考虑花费的话. S -> 摄像头 -> 苹果 -> T 就相当于找到一个最小割使得S和T分开. ans = sum - flow. 然后对于这一个模型, ...

随机推荐

  1. CF #552 div3

    A - Restoring Three Numbers CodeForces - 1154A Polycarp has guessed three positive integers aa, bb a ...

  2. Linux - NodeJS安装

    1> 去NodeJS官网 https://nodejs.org/en/ 或 中文网 http://nodejs.cn/download/ 拷贝相应版本的安装文件,如下图: 2> 执行 wg ...

  3. VMware12全新安装CentOS-6.9模板机(已优化)

    1.从安装系统开始准备 安装中添加网卡 eth0 ip 10.0.0.210 netmask 24 gateway 10.0.0.254 DNS servers 223.5.5.5 eth1 ip 1 ...

  4. PHP redis使用命令

    很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__constru ...

  5. ubuntu中卸载没有安装完全的软件包

    sudo apt-get autoclean sudo apt-get clean sudo apt-get autoremove

  6. Python中类的声明,使用,属性,实例属性,计算属性及继承,重写

    Python中的类的定义以及使用: 类的定义: 定义类 在Python中,类的定义使用class关键字来实现 语法如下: class className: "类的注释" 类的实体 ...

  7. Python全栈之jQuery笔记

    jQuery runnoob网址: http://www.runoob.com/jquery/jquery-tutorial.html jQuery API手册: http://www.runoob. ...

  8. 解决VMware vSphere Client无法连接ESXi虚拟主机方法

    1 一般情况下重启services.sh就可以解决(或图形界面下restart management agent)services.sh restart2 若重启services.sh报错且仍然无法连 ...

  9. Python虚拟机函数机制之位置参数(四)

    位置参数的传递 前面我们已经分析了无参函数的调用过程,我们来看看Python是如何来实现带参函数的调用的.其实,基本的调用流程与无参函数一样,而不同的是,在调用带参函数时,Python虚拟机必须传递参 ...

  10. RHEL6.X设置163yum源

    目录 RHEL6.X设置163yum源 卸载系统的yum 检查是否已经卸载完成 下载yum以及相关包 安装yum相关rpm包 清除原有缓存,建立yum列表 本地yum源设置 挂载本地光盘 修改配置文件 ...