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

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

题意:一个电脑游戏,有各种颜色的光圈,题目要求你从红色光圈到紫色光圈再回到红色光圈(中间可已经经过其他颜色的光圈)光圈形状为圆形

要求:1、如果两个光圈相交,则可以从光谱大的走到光谱小的

2、紫色光圈和红色光圈可以走两次,别的颜色的只能走一次

问是否能够实现要求

题解:建立超级源点0,超级汇点n+1

1、紫色光圈连接源点权值为2

2、红色光圈连接汇点权值为2

3、其他颜色光圈  光谱大的连接到光谱小的,权值为1;

如果最大流为2则可以完成,

#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;
}

  

时间: 2024-10-15 00:11:09

hdoj 4183 Pahom on Water的相关文章

hdoj 4183 Pahom on Water 【基础最大流】

题目:hdoj 4183 Pahom on Water 题意:题目有点长,读懂了就是个水的最大流,每次从789开始到400,走的话必须是两个圆相交而且频率递增的,每个点只走一次,求有没有满足这样条件的. 分析:题目读懂就比较水了.直接按照题目意思建图,初始点和结束点容量为2,其他点只走一次容量为1,然后求最大流. AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <str

HDU 4183 Pahom on Water 来回走不重复点的网络流

题目来源:HDU 4183 Pahom on Water 题意:若干个区域 每个区域有一个值 区域是圆 给出圆心和半径 从起点(值为400.0)到终点(值为789.0)满足走相交的圆 并且值必须递增 然后从终点到起点 值必须递减 此外区域只能去一次 思路:建图 相互能走的区域连一条边 因为只能走一次 所以拆点 如果没有来回 只有去 那么判断最大流为1即可 现在还要回来 并且回来的条件和去的条件想法(一个递增一个递减)可以反向考虑给源点cap=2 最大流为2 #include <cstdio>

HDU 4183 Pahom on Water(最大流SAP)

Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 629    Accepted Submission(s): 288 Problem Description Pahom on Water is an interactive computer game inspired by a short story of

【HDOJ】4183 Pahom on Water

就是一个网络流.red结点容量为2,查看最大流量是否大于等于2.对于条件2,把边反向加入建图.条件1,边正向加入建图. 1 /* 4183 */ 2 #include <iostream> 3 #include <string> 4 #include <map> 5 #include <queue> 6 #include <set> 7 #include <stack> 8 #include <vector> 9 #inc

HDU 4183 Pahom on Water(最大流)

https://vjudge.net/problem/HDU-4183 题意: 这道题目的英文实在是很难理解啊. 给出n个圆,每个圆有频率,x.y轴和半径r4个属性,每次将频率为400的圆作为起点,频率为789点作为终点.从源点到汇点时必须从频率小的到频率大的,而从汇点到源点时必须从频率大的到频率小的.前提时这两个圆必须严格相交.每个点只能走一次.判断是否能从起点出发到达终点,并再次返回起点. 思路: 其实就是判断最大流是否大于等于2.因为每个点只能走一次,用拆点法. 1 #include<io

【网络流】 HDU 4183 Pahom on Water 拆点

题意:求两条路 能从 400.0 -> 789.0 且这两条路不想交(除了端点400,789 ) 求只能走一次的网络流需要用到拆点, 将点i  拆成 i 和 i+n  i->i+n的容量为经过的次数  (这题为1 ) 若i 能到达 j  则连接 i+n-> j #include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <iost

HDOJ 4974 A simple water problem

A simple water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 173    Accepted Submission(s): 112 Problem Description Dragon is watching competitions on TV. Every competition is held be

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

题意: 有n个圆,每个圆的中心和半径和一个频率都给定,只有一个频率最高的789为紫色,只有一个最低的400为红色,规则如下: 1.当两个圆严格相交时,且人是从红色到紫色的方向运动时可以由低频率向高频率移动 2.当两个圆严格相交时,且人是从紫色到红色的方向运动时可以由高频率向低频率运动 3.除了红色的圆以外,离开某个圆之后就会消失(即只能走一次) 思路: 如果一开始红色和紫色就相交,则存在合理方案.否则 本题要求是先从红点出发,经过紫点之后再返回红点,如果以红点作为源点,网络流算法不能先到达一个T

hdu 最大流例题

1532 Drainage Ditches(入门)    [最大流]3549 Flow Problem(入门)    [最大流]3572 Task Schedule(基础)    [最大流]任务分配,判断满流2732 Leapin' Lizards(较难)    [最大流]3338 Kakuro Extension(较难,好题)    [最大流][数和]神奇最大流行进列出2883 kebab(中等)    [最大流]判断满流3605 Escape(中等,好题)    [最大流](可用多重匹配)4