hdoj 4183 Pahom on Water
Pahom on Water
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 772 Accepted Submission(s):
355
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.
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”.
that contains: Game is VALID, or Game is NOT VALID
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#include<algorithm>
#define INF 0x7ffffff
#define MAX 10010
#define MAXM 100100
#define eps 1e-5
#define DD double
using namespace std;
DD pad[MAX],x[MAX],y[MAX],r[MAX];
struct node
{
int from,to,cap,flow,next;
}edge[MAXM];
int vis[MAX],dis[MAX];
int cur[MAX];
int head[MAX],ans;
void init()
{
ans=0;
memset(head,-1,sizeof(head));
}
void add(int u,int v,int w)
{
edge[ans]={u,v,w,0,head[u]};
head[u]=ans++;
edge[ans]={v,u,0,0,head[v]};
head[v]=ans++;
}
int judge(int i,int j)//判断两个光谱是否相交
{
if((sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j])<0)
return 1;
return 0;
}
int bfs(int beg,int end)
{
memset(vis,0,sizeof(vis));
memset(dis,-1,sizeof(dis));
queue<int>q;
while(!q.empty())
q.pop();
q.push(beg);
vis[beg]=1;
dis[beg]=0;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u];i!=-1;i=edge[i].next)
{
node E=edge[i];
if(!vis[E.to]&&E.cap>E.flow)
{
dis[E.to]=dis[u]+1;
vis[E.to]=1;
if(E.to==end) return 1;
q.push(E.to);
}
}
}
return 0;
}
int dfs(int x,int a,int end)
{
if(a==0||x==end)
return a;
int flow=0,f;
for(int &i=cur[x];i!=-1;i=edge[i].next)
{
node& E=edge[i];
if(dis[E.to]==dis[x]+1&&(f=dfs(E.to,min(a,E.cap-E.flow),end))>0)
{
E.flow+=f;
edge[i^1].flow-=f;
flow+=f;
a-=f;
if(a==0) break;
}
}
return flow;
}
int Maxflow(int beg,int end)
{
int flow=0;
while(bfs(beg,end))
{
memcpy(cur,head,sizeof(head));
flow+=dfs(beg,INF,end);
}
return flow;
}
int main()
{
int t,n,m,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
init();
for(i=1;i<=n;i++)
scanf("%lf%lf%lf%lf",&pad[i],&x[i],&y[i],&r[i]);
for(i=1;i<=n;i++)
{
if(fabs(pad[i]-789.0)<=eps)//紫色光圈连接源点
add(0,i,2);
if(fabs(pad[i]-400.0)<=eps)//红则光谱连接汇点
add(i,n+1,2);
for(j=1;j<=n;j++)
{
if(i!=j)//判断到同一个光圈时跳过
{
if(judge(i,j)&&pad[i]>pad[j])//光圈相交且第一个的光普大
{
add(i,j,1);
}
}
}
}
if(Maxflow(0,n+1)==2)
printf("Game is VALID\n");
else
printf("Game is NOT VALID\n");
}
return 0;
}
hdoj 4183 Pahom on Water的更多相关文章
- HDU 4183 Pahom on Water(最大流SAP)
Pahom on Water Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 【HDOJ】4183 Pahom on Water
就是一个网络流.red结点容量为2,查看最大流量是否大于等于2.对于条件2,把边反向加入建图.条件1,边正向加入建图. /* 4183 */ #include <iostream> #in ...
- HDU 4183 Pahom on Water(最大流)
https://vjudge.net/problem/HDU-4183 题意: 这道题目的英文实在是很难理解啊. 给出n个圆,每个圆有频率,x.y轴和半径r4个属性,每次将频率为400的圆作为起点,频 ...
- Pahom on Water(最大流)
Pahom on Water Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDOJ 4974 A simple water problem
A simple water problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU4183 Pahom on Water(来回走最大流,一个点只经过一次)
题意: 有n个圆,每个圆的中心和半径和一个频率都给定,只有一个频率最高的789为紫色,只有一个最低的400为红色,规则如下: 1.当两个圆严格相交时,且人是从红色到紫色的方向运动时可以由低频率向高频率 ...
- hdu 4183 EK最大流算法
欢迎参加——每周六晚的BestCoder(有米!) Pahom on Water Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327 ...
- hdu 4183(网络流)
Pahom on Water Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDOJ 4009 Transfer water 最小树形图
Transfer water Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) T ...
随机推荐
- <二> SQL 基础
left (outer) join 结果集包含连接表的匹配行,也包括左连接表的所有行. select a.a, a.b, a.c, b.c b.d b.f from a left out join b ...
- Almeza MultiSet Pro(批量安装程序) V8.7.6中文特别版
Almeza MultiSet Pro(批量安装程序)是一款非常实用的工具.它能够帮你批量地安装常用的软件.这将解决每次重装系统后能够快速方便地重装常用软件.使用这款软件不需要编写程序,还可以在安装过 ...
- Java之向左添加零(000001)第二种方法
//待测试数据 int i = 100; //得到一个NumberFormat的实例 NumberFormat nf = NumberFormat.getInstance(); //设置是否使用分组 ...
- ruby的gem和boundle安装解决办法
gem和boundle安装在国内被墙,淘宝提供了淘宝提供了RubyGems的国内镜像站点,解决办法是: 对于gem: $ gem sources --remove https://rubygems.o ...
- Hadoop集群系类文章
http://www.cnblogs.com/xia520pi/archive/2012/04/08/2437875.html 后续文章地址:http://www.xiapistudio.com/ta ...
- JSON漫谈
JSON: JavaScript Object Notation(JavaScript 对象表示法),JSON 是存储和交换文本信息的语法.类似 XML.JSON 比 XML 更小.更快,更易解析. ...
- PHP reset() 函数
定义和用法 reset()函数把数组的内部指针指向第一个元素,并返回这个元素的值.若失败,则返回 FALSE. reset()函数用来将数组指针设置回数组的开始位置.如果需要在一个脚本中多次查看或处理 ...
- 【Linux安全】系统资源监控与进程终止
linux系统允许多用户同时操作,当用户量非常大且占用系统资源非常严重的时候, 管理员想要分析一下资源的占用情况,而在linux中有没有类似于windows系统的 资源管理器一样的工具呢,答案是肯定的 ...
- Android 多屏幕适配
问题: 测试时,发现应用在不同的显示器上显示效果不同(部分文本不能显示完全),自然想到屏幕适配的问题. 按照思路整理如下: (一) 几个概念 1, Screen size 屏幕的尺寸,即对角线长度(单 ...
- Android 在AlertDialog里添加布局控件
android里很多时候需要在弹出的AlertDialog里有自己的控件,填写信息,比如弹出一个登陆对话框 那么首先你就要创建这么一个布局的inputphonenum.xml文件了 <?xml ...