[Edge required for full binary match] poj 1486

Source: Internet
Author: User

At the beginning, I did not see the question clearly. I went straight to the Hungary algorithm and saw a sentence later.Then print a series of all the slides whose numbers can be uniquely determined from the input

The output must be unique! It is to ask whether each edge is unique. Practice: first use Hungary to find a match, and then split the edge one by one. If another matches completely, it is none. Otherwise, the result can be output. Note that the I of Match [I] = J is X, and J is Y.

# Include <map> # include <set> # include <list> # include <queue> # include <deque> # include <stack> # include <string> # include <cstdio> # include <math. h> # include <iomanip> # include <cstdlib> # include <limits. h> # include <string. h> # include <iostream> # include <fstream> # include <algorithm> using namespace STD; # define ll long # define Min-9999999 # define Max int_max # define PII pair <int, int> # define bug cout <"here !! "<Endl # define PI ACOs (-1.0) # define fre freopen (" input.txt "," r ", stdin) # define FF freopen (" output.txt "," W ", stdout) # define EPS 1e-8 # define n 1005int min (int A, int B) {return A> B? B: A;} int max (int A, int B) {return A> B? A: B;} bool G [N] [N], vis [N]; int match [N]; int N; int ans [N]; struct re {int xmin, xmax, ymin, Ymax;} p [N]; struct node {int X, Y;} Q [N]; bool sear (int x) {// Hungarian algorithm for (INT I = 0; I <n; I ++) {If (G [x] [I] &! Vis [I]) {vis [I] = 1; if (Match [I] =-1 | sear (Match [I]) {match [I] = x; return true ;}} return false;} bool chk (int I, Int J) {If (Q [J]. x> = P [I]. xmin & Q [J]. x <= P [I]. xmax & Q [J]. y> = P [I]. ymin & Q [J]. Y <= P [I]. ymax) return true; return false;} void Gao () {int I, j; bool OK = 0; for (I = 0; I <n; I ++) {int TMP = match [I]; G [TMP] [I] = 0; match [I] =-1; memset (VIS, 0, sizeof (VIS )); if (! Sear (TMP) {If (OK) printf (""); printf ("(% C, % d)", I + 'A', TMP + 1 ); OK = 1; match [I] = TMP;} G [TMP] [I] = 1;} If (! OK) {puts ("None \ n");} else {printf ("\ n") ;}} int main () {int T = 1; while (scanf ("% d", & N) {int I, j; memset (G, 0, sizeof (g); for (I = 0; I <n; I ++) {scanf ("% d", & P [I]. xmin, & P [I]. xmax, & P [I]. ymin, & P [I]. ymax); match [I] =-1 ;}for (I = 0; I <n; I ++) {scanf ("% d ", & Q [I]. x, & Q [I]. y) ;}for (I = 0; I <n; I ++) {for (j = 0; j <n; j ++) {If (chk (I, j) {G [J] [I] = 1 ;}} int CNT = 0; for (I = 0; I <n; I ++) {memset (VIS, 0, sizeof (VIS )); If (SEAR (I) CNT ++;} printf ("heap % d \ n", t ++); If (CNT! = N) {puts ("NONE"); puts ("") ;}else {Gao () ;}} return 0 ;}

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.