Pahom on Water

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

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

题解:题意就是光圈相交了才能走,只能从频率大的到小的,问是否能从红光到紫光再回到红光,红光到紫光频率要从小到大<<<<紫光到红光频率要从大到小>>>>>,由此直接红光与源点连,紫光连汇点,频率从小到大,就加边,能从红到紫,自然能从紫到红了;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
const int INF=0x3f3f3f3f;
const int MAXN=;
const int MAXM=<<;
struct Edge{
int from,to,next,cup,flow;
};
Edge edg[MAXM];
int head[MAXM],dis[MAXN],edgnum,vis[MAXN],h[MAXM];
void initial(){
edgnum=;mem(head,-);
}
struct Dot{
double fq,x,y,r;
}dt[];
void add(int u,int v,int w){
Edge E={u,v,head[u],w,};
edg[edgnum]=E;
head[u]=edgnum++;
E={v,u,head[v],,};
edg[edgnum]=E;
head[v]=edgnum++;
}
bool bfs(int s,int e){
mem(dis,-);mem(vis,);
queue<int>dl;
dis[s]=;vis[s]=;dl.push(s);
while(!dl.empty()){
int u=dl.front();
dl.pop();
for(int i=head[u];i!=-;i=edg[i].next){
Edge v=edg[i];
if(!vis[v.to]&&v.cup-v.flow){
vis[v.to]=;
dis[v.to]=dis[u]+;
dl.push(v.to);//
if(v.to==e)return true;
}
}
}
return false;
}
int dfs(int x,int la,int e){ if(x==e||la==)return la;
int temp,flow=;
for(int i=h[x];i!=-;i=edg[i].next){
Edge &v=edg[i];
if(dis[v.to]==dis[x]+&&(temp=dfs(v.to,min(la,v.cup-v.flow),e))>){
flow+=temp;
v.flow+=temp;
edg[i^].flow-=temp;
la-=temp;
if(la==)break;
}
}
return flow;
}
int maxflow(int s,int e){
int flow=;
while(bfs(s,e)){
memcpy(h,head,sizeof(head));
flow+=dfs(s,INF,e);
}
return flow;
}
bool judge(Dot a,Dot b){
if(a.fq<b.fq&&(pow(b.x-a.x,)+pow(b.y-a.y,)<pow(b.r+a.r,)))return true;
return false;
}
int main(){
int k,N;
scanf("%d",&k);
while(k--){
initial();
scanf("%d",&N);
for(int i=;i<=N;i++){
scanf("%lf%lf%lf%lf",&dt[i].fq,&dt[i].x,&dt[i].y,&dt[i].r);
if(fabs(789.0-dt[i].fq)<=1e-)add(i,N+,);
if(fabs(dt[i].fq-400.0)<=1e-)add(,i,);
}
for(int i=;i<=N;i++){
for(int j=;j<=N;j++){
if(i==j)continue;
if(judge(dt[i],dt[j]))add(i,j,);
}
}
if(maxflow(,N+)==)puts("Game is VALID");
else puts("Game is NOT VALID");
}
return ;
}

Pahom on Water(最大流)的更多相关文章

  1. HDU 4183 Pahom on Water(最大流SAP)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. hdoj 4183 Pahom on Water

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. HDU 4183 Pahom on Water(最大流)

    https://vjudge.net/problem/HDU-4183 题意: 这道题目的英文实在是很难理解啊. 给出n个圆,每个圆有频率,x.y轴和半径r4个属性,每次将频率为400的圆作为起点,频 ...

  4. HDU4183 Pahom on Water(来回走最大流,一个点只经过一次)

    题意: 有n个圆,每个圆的中心和半径和一个频率都给定,只有一个频率最高的789为紫色,只有一个最低的400为红色,规则如下: 1.当两个圆严格相交时,且人是从红色到紫色的方向运动时可以由低频率向高频率 ...

  5. 【HDOJ】4183 Pahom on Water

    就是一个网络流.red结点容量为2,查看最大流量是否大于等于2.对于条件2,把边反向加入建图.条件1,边正向加入建图. /* 4183 */ #include <iostream> #in ...

  6. hdu 4183 EK最大流算法

    欢迎参加——每周六晚的BestCoder(有米!) Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327 ...

  7. hdu 4183(网络流)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. HDU 4183Pahom on Water(网络流之最大流)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4183 这题题目意思非常难看懂..我看了好长时间也没看懂..终于是从网上找的翻译. .我就在这翻译一下吧 ...

  9. [LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流

    Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...

随机推荐

  1. 五子棋Web版的开发(二)--整合Spring4.3+hibernate4+Struts2.3

    拖了这么久才把ssh框架给整合完毕,期间发现自己对SSH的知识真的是知之甚少.在整合期间遇到了无数的坑,我还是先把项目地址发一下吧 首先我遇到的第一个问题是 CreateQuery is not va ...

  2. EasyUI的使用步骤

    (1) 将easyui-1.4.3中jquery.min.js\jquery.easyui.min.js复制到工程的script下 (2) 将themes复制到工程中 (3) 在页面中引入2个JS 2 ...

  3. ubuntu16.04安装kde桌面出错: /var/cache/apt/archives/kde-config-telepathy-accounts_4%3a15.12.3-0ubuntu1_amd64.deb

    出错提示: 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 kubuntu-desktop 已经是最新版 (1.338). 您可能需要运行“apt-get - ...

  4. POJ2823 Sliding Window(单调队列)

    单调队列,我用deque维护.这道题不难写,我第二次写单调队列,1次AC. -------------------------------------------------------------- ...

  5. 200常用JS

    .文本框焦点问题 onBlur:当失去输入焦点后产生该事件 onFocus:当输入获得焦点后,产生该文件 Onchange:当文字值改变时,产生该事件 Onselect:当文字加亮后,产生该文件 &l ...

  6. [转] iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用

    介绍: Grand Central Dispatch 简称(GCD)是苹果公司开发的技术,以优化的应用程序支持多核心处理器和其他的对称多处理系统的系统.这建立在任务并行执行的线程池模式的基础上的.它首 ...

  7. LintCode-不同的子序列

    题目描述: 给出字符串S和字符串T,计算S的不同的子序列中T出现的个数. 子序列字符串是原始字符串通过删除一些(或零个)产生的一个新的字符串,并且对剩下的字符的相对位置没有影响.(比如,“ACE”是“ ...

  8. spss

    编辑 SPSS(Statistical Product and Service Solutions),“统计产品与服务解决方案”软件.最初软件全称为“社会科学统计软件包” (SolutionsStat ...

  9. Storm几篇文章

    http://tianhailong.com/ http://www.cnblogs.com/panfeng412/archive/2012/07/02/storm-common-patterns-o ...

  10. 利用bind搭建dns

    下载bind,我下载的是bind-9.3.1rc1.tar.gz 我下载的文件放在/root目录下 进入目录解压缩 [root@linux root]#tar xfz bind-9.3.1rc1.ta ...