Hdu 4183 ek maximum flow algorithm

Source: Internet
Author: User


Welcome to the Bestcoder-every Saturday night (with rice!) )
Pahom on water

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 678 Accepted Submission (s): 312


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

The title of the question is difficult to read. I haven't read it for a long time. The final translation is from the Internet. I'll translate it here.

The meaning is about: There are multiple points, each point given the coordinates and radius, add two points intersect, you can go from these two points. The topic requires starting from the beginning to the end, and then back to the starting point. From the beginning to the end of the process, only from the frequency of small to go to the point of large frequency (provided that two points intersect), from the end to the beginning of the process, only from the frequency of large to the frequency of small. In the process of walking, in addition to the beginning and the end, the other as long as the walk will disappear, that is, only to walk once. Ask if you can get back to the beginning from the beginning to the end.

The first day to see no ideas, and then a think, is nothing but from the beginning to the end of the walk two times, are from small to large, and the middle of the point is not repeated. Then it's easy to build the map. To ensure that each point only walks once, the weight can be set to 1, so that each step can only go once. Then see if the maximum flow is greater than or equal to 2. It is also important to note that if you can directly from the beginning to the end, you do not have to judge, certainly can meet the requirements.

#include <stdio.h>#include<string.h>#include<iostream>#include<queue>#include<algorithm>using namespacestd;Const intinf=0x7fffffff;intedge[ -][ -];//adjacency Matrixintdis[ -];//distance from source point, hierarchical graphintStart,end;intM,n;//N: points; M, number of sidesstructnode{Doubles; intX,y,r;} que[ -];BOOLConintIintj) {      if((que[i].x-que[j].x) * (que[i].x-que[j].x) + (QUE[I].Y-QUE[J].Y) * (QUE[I].Y-QUE[J].Y)) < (QUE[I].R+QUE[J].R) * (que [i].r+QUE[J].R)) return true; Else        return false;}intMaxflow, pre[ -];voidEdmonds_karp (intStartintEndintm) {     while(1) {Queue<int>p; intMinflow =inf;        P.push (start); memset (PRE,0,sizeof(pre));  while(!Q.empty ()) {            intU =P.front ();            P.pop (); if(U = =end) Break;  for(inti =1; I <= m;i++)                if(Edge[u][i] >0&&pre[i] = =0) {Pre[i]=u;                P.push (i); }        }        if(Pre[end] = =0)             Break;  for(inti = end;i! = Start;i =Pre[i]) Minflow=min (Minflow, edge[pre[i]][i]);  for(inti = end;i! = Start;i =Pre[i]) {Edge[pre[i]][i]-=Minflow; Edge[i][pre[i]]+=Minflow; } Maxflow+=Minflow; }}intMain () {intT; scanf ("%d",&t);  while(t--) {memset (que,0,sizeof(que)); Memset (Edge,0,sizeof(Edge)); intN; scanf ("%d",&N);  for(intI=1; i<=n;i++) {scanf ("%lf%d%d%d",&que[i].s,&que[i].x,&que[i].y,&QUE[I].R); }        for(intI=1; i<=n;i++){           if(que[i].s==400.0) {Start=i; }            if(que[i].s==789.0) {End=i; }       }        for(intI=1; i<=n;i++){         for(intj=i+1; j<=n;j++){            if(Con (i,j)) {if(que[i].s>que[j].s) Edge[j][i]=1; Else if(que[j].s>que[i].s) Edge[i][j]=1; } }} maxflow=0;       Edmonds_karp (Start, end, N); if(maxflow>=2) printf ("Game is valid\n"); Elseprintf ("Game is not valid\n"); }   return 0;}

Hdu 4183 ek maximum flow algorithm

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.