Hdoj 4183 Pahom on water

Source: Internet
Author: User

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 Descriptionpahom on water are an interactive computer game inspired by a short stories of Leo Tolstoy about a poor Ma n Who, in he 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 is painted with the same colour (defined by a certain frequency) except for the one, Colours red and Violet. The display contains only one red pad (the lowest frequency of the THz) and one violet pad (the highest frequency of 789 T HZ). 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 of 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 freq Uency 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 FRE Quency 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 have programmed all the Whizzbang features of the game. All that are left are to ensure that Pahom have a chance to succeed in each instance of the the game (which is, there are at least One valid walk from the red pad to the violet pad and then back again to the red pad.) Your task is-write a program-to-check whether at least one valid path exists in each instance of the game.

Inputthe input starts with an integer k (1 <= k <=) indicating the number of scenarios in a line by itself. The description for each scenario starts with an integer n (2 <= N <=) 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 is given, in meters, as integers. All values is separated by a single space. All integer values is in the range of-10,000 to inclusive. In each scenario, all frequencies is in the range of 400.0 to 789.0 inclusive. Exactly one pad would have a frequency of "400.0" and exactly one pad would have a frequency of "789.0".

Outputthe output For each scenario consists of a single line that contains:game are VALID, or Game is not VALID

Sample Input22 400.0 0 0 4789.0 7 0 24400.0 0 0 4789.0 7 0 2500.35 5 0 2500.32 5 0 3

Sample Outputgame is isn't validgame is VALID test instructions: A computer game with a variety of color aperture, the topic requires you from the red aperture to the purple aperture and then back to the red aperture (in the middle can already pass other color aperture) aperture shape for circular requirements: 1, If the two aperture intersection, you can go from the spectrum to a small spectrum of 2, purple aperture and red aperture can walk two times, other colors can only walk once asked whether it is possible to achieve the requirements of the question: to establish a super-source 0, Super sinks n+11, purple aperture Connection source point weight 22, red aperture connection sink weight 23, Other color aperture spectra large connected to the spectral small, weighted value of 1, if the maximum flow of 2 can be done,
#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 Doubleusing 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);} 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)//Determine if two spectra intersect {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)//Violet aperture Connection source point Add (0,i,2);        if (Fabs (pad[i]-400.0) <=eps)//Red spectral Connection meeting point Add (i,n+1,2); for (j=1;j<=n;j++) {if (I!=J)//When judging to the same aperture, skip {if (Judge (I,j) &&pad[i]>pad[j])//Aperture intersection        And the first one of the big pop {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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.