HDU 4183 Pahom on water (Max stream SAP)

Source: Internet
Author: User

Pahom on waterTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 629 Accepted Submission (s): 288


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 Input
22 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 Output
Game is isn't validgame is VALID

Sourcethe South Pacific Programming Contest

Test instructions: Just give n pad (liner) Next each row represents a pad, each pad has a color frequency F, the center coordinate (x, y) and radius R. Now from the color frequency f==400 pad began to go to f==789.0 pad, so the rule is two circles have intersection and F [U]<f[v] Description can be from U-->v. From f==789.0 to f==400, the rule is that the two circles have intersections and f[u]>f[v] indicate that they can be from u-->v. Ask if there is such a way out of the starting point and back to the starting point. (Cannot pass the same edge)

Solve the problem: Because from the beginning S to the end point T and then back to S, cannot go through the same side. In fact, is to find two from the S-->t road, through the side can not be the same, to meet the requirements. Build: Liner U, liner V, if F[U]<F[V] and two circles have intersection, then build an edge, contents is 1.

#include <stdio.h> #include <string.h> #include <queue> #include <algorithm> #include <   math.h>using namespace std; #define Captype intconst int maxn = 100010;    Total number of points const int MAXM = 400010;    Total number of edges const int INF = 1<<30;struct edg{int to,next; Captype Cap,flow;}  Edg[maxm];int Eid,head[maxn];int GAP[MAXN];  The number of points for each distance (or can be considered a height) int DIS[MAXN];  The shortest distance from each point to the end Enode int CUR[MAXN];    Cur[u] indicates that from the U point can flow through the cur[u] number side int pre[maxn];void init () {eid=0; memset (head,-1,sizeof (Head));}    There are three parameters to the edge, 4 parameters void addedg (int u,int v,captype c,captype rc=0) without a forward edge {edg[eid].to=v; edg[eid].next=head[u]; Edg[eid].cap=c; edg[eid].flow=0;    head[u]=eid++; Edg[eid].to=u;    EDG[EID].NEXT=HEAD[V]; EDG[EID].CAP=RC; edg[eid].flow=0; head[v]=eid++;}    Captype maxflow_sap (int snode,int enode, int n) {//n is the total number of points including the source and sink points, this must be noted memset (Gap,0,sizeof (GAP));    memset (dis,0,sizeof (dis));    memcpy (cur,head,sizeof (head));    Pre[snode] =-1;    Gap[0]=n;  Captype ans=0; Max Stream int U=sNode;            while (dis[snode]<n) {//determines from SNode point there is no flow to the next adjacent point if (u==enode) {//Find a way to add flow captype min=inf;            int inser;                for (int i=pre[u]; i!=-1; i=pre[edg[i^1].to])//To find the maximum amount of traffic Min if (min>edg[i].cap-edg[i].flow) {                Min=edg[i].cap-edg[i].flow;            Inser=i;                } for (int i=pre[u]; i!=-1; i=pre[edg[i^1].to]) {edg[i].flow+=min;  Edg[i^1].flow-=min;            Flow of the side that can be recycled} ans+=min;            u=edg[inser^1].to;        Continue  } bool flag = FALSE;        It is possible to determine whether an int v can flow toward the neighboring point from the U point;            for (int i=cur[u]; i!=-1; i=edg[i].next) {v=edg[i].to;                if (edg[i].cap-edg[i].flow>0 && dis[u]==dis[v]+1) {flag=true;                Cur[u]=pre[v]=i;            Break            }} if (flag) {u=v;        Continue }//If a flow adjacent point is not found above, then the distance from the starting point U (which can also be considered a height) is adjacentThe minimum distance of the flow point is +1 int mind= n;            for (int i=head[u]; i!=-1; i=edg[i].next) if (edg[i].cap-edg[i].flow>0 && mind>dis[edg[i].to]) {            MIND=DIS[EDG[I].TO];        Cur[u]=i;        } gap[dis[u]]--;  if (gap[dis[u]]==0) return ans; When Dis[u] The point of this distance is gone, it is impossible to find an augmented stream path from the source point//Because there is only one distance from the sink point to the current point, then from the source point to the sink point must pass the current point, but the current point is not able to find        Can flow to the point, then the inevitable flow of dis[u]=mind+1;//if a stream of adjacent points is found, the distance is the distance of the adjacent point +1, if not found, then the n+1 gap[dis[u]]++;  if (U!=snode) u=edg[pre[u]^1].to; Return an Edge} return ans; struct node{double f,x,y,r;} A[305];d ouble ABS (double rr) {return RR&GT;0?RR:-RR;}    BOOL Judge (int I,int j) {if (A[I].F&GT;=A[J].F) return 0;    Double D=sqrt ((a[i].x-a[j].x) * (a[i].x-a[j].x) + (A[I].Y-A[J].Y) * (A[I].Y-A[J].Y)); if (a[i].r+a[j].r<d| |    D<abs (A[I].R-A[J].R)) return 0; return 1;}    int main () {int t,n;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        Init (); int S, T            for (int i=1; i<=n; i++) {scanf ("%lf%lf%lf%lf", &AMP;A[I].F,&AMP;A[I].X,&AMP;A[I].Y,&AMP;A[I].R);            if (a[i].f==400.0) s=i;        else if (a[i].f==789.0) t=i;                } for (int i=1, i<=n; i++) for (int j=1; j<=n; J + +) if (I!=j&&judge (I,J))         ADDEDG (i,j,1);         int ans = MAXFLOW_SAP (s,t,n);         if (ans>1) printf ("Game is valid\n");    else printf ("Game is not valid\n"); }}


HDU 4183 Pahom on water (Max stream SAP)

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.