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 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
Source the Pacific programming Contest test Instructions: There are some points on the plane, they have their coordinates, the frequency, the radius, the condition that can be from one point to another point is that the distance of two points is less than the sum of the radius. Now we have to go from the lowest frequency point to the most frequent point, the rule is only from the frequency of small to go to the frequency, and then back again, the rule is exactly the opposite, asked whether there is such a scheme to make the above conditions. The problem: Merging the second rule with the first rule, the question becomes whether there are two different paths so that the starting point (f lowest) can reach the end point (f highest), and then the composition, the frequency of low to high frequency with a capacity of 1 edge, so that you can guarantee that each edge up to go once, The maximum stream is then calculated, and if the maximum stream is greater than or equal to 2, there are two paths.
#include <stdio.h>#include<algorithm>#include<queue>#include<string.h>#include<math.h>using namespacestd;Const intN = -;Const intINF =999999999;intCap[n][n];intFlow[n];intPre[n];intN;structnode{intX,y,r; DoubleF;} Node[n];Doubledis (Node a,node b) {returnsqrt1.0* ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-B.Y))) ;}intBFsintSrcintdes) {Queue<int>Q; for(intI=1; i<=des;i++) {Pre[i]=-1; } PRE[SRC]=0; FLOW[SRC]=INF; Q.push (SRC); while(!Q.empty ()) { intU =Q.front (); Q.pop (); if(U==des) Break; for(intI=1; i<=des;i++){ if(i!=src&&cap[u][i]>0&&pre[i]==-1) {Pre[i]=u; Flow[i]=min (cap[u][i],flow[u]); Q.push (i); } } } if(pre[des]==-1)return-1; returnflow[des];}intMax_flow (intSrcintdes) { intAns =0, Increaseroad; while((Increaseroad=bfs (src,des))!=-1){ intK =des; while(k!=src) {Cap[pre[k]][k]-=Increaseroad; CAP[K][PRE[K]]+=Increaseroad; K=Pre[k]; } ans+=Increaseroad; } returnans;}intCMP (Node A,node b) {returna.f<B.f;}voidbuild () {scanf ("%d",&N); memset (Cap,0,sizeof(CAP)); for(intI=1; i<=n;i++) {scanf ("%lf%d%d%d",&node[i].f,&node[i].x,&node[i].y,&NODE[I].R); } Sort (Node+1, node+n+1, CMP); for(intI=1; i<=n;i++){ for(intj=i+1; j<=n;j++){ if(I!=j&&dis (Node[i],node[j]) <= (node[i].r+NODE[J].R)) {Cap[i][j]=1; } } }}intMain () {inttcase; scanf ("%d",&tcase); while(tcase--) {build (); intt = Max_flow (1, N); if(t>=2) printf ("Game is valid\n"); Elseprintf"Game is not valid\n"); }}
HDU 4183 (Network stream)