PKU 1486 sorting slides

Source: Internet
Author: User

The position of the Maxx, Minx, Maxy, miny, and N points of N slides indicates the slide number, which is written on the slide, ask if the maximum match between the slide and the serial number can be used to determine the unique match, and output the identified unique match;

Analysis: if the number and slide meet the requirements of Minx <x <Maxx, miny <Y <Maxy, a possible match is formed and the maximum match is obtained (it must be a perfect match, then, judge whether the matching edge is a required edge.

Determination Method: First Delete the matching edge to determine whether there is an augmented path from this point. If so, it is not a required edge. Otherwise, it is a required edge;

# Include <iostream> using namespace STD; bool mat [26] [26], vis [26]; int MX [26], my [26], N; struct slide {int xmin, xmax, ymin, Ymax;} s [26]; struct point {int X, Y;} p [26]; int path (int s) {for (INT I = 0; I <n; I ++) if (MAT [s] [I] &! Vis [I]) {vis [I] = 1; if (my [I] =-1 | path (my [I]) {my [I] = s; MX [s] = I; return 1 ;}} return 0 ;}bool judge (int I, Int J) {If (P [J]. x <s [I]. xmax & P [J]. x> S [I]. xmin & P [J]. Y <s [I]. ymax & P [J]. y> S [I]. ymin) return true; return false;} int main () {int CAS = 0; while (scanf ("% d", & n) = 1 & N) {for (INT I = 0; I <n; I ++) scanf ("% d", & S [I]. xmin, & S [I]. xmax, & S [I]. ymin, & S [I]. ymax); For (INT I = 0; I <n; I ++) scanf ("% d", & P [I]. x, & P [I]. y); memset (MAT, 0, sizeof (MAT); memset (My,-1, sizeof (my); memset (MX,-1, sizeof (MX )); for (INT I = 0; I <n; I ++) for (Int J = 0; j <n; j ++) {If (Judge (I, j )) mat [I] [J] = 1 ;}for (INT I = 0; I <n; I ++) if (MX [I] =-1) {memset (VIS, 0, sizeof (VIS); Path (I);} printf ("heap % d \ n", ++ CAS); int flag = 1; for (INT I = 0; I <n; I ++) {int y = Mx [I]; MX [I] =-1; my [y] =-1; mat [I] [Y] = 0; memset (VIS, 0, sizeof (VIS); If (! PATH (I) {If (FLAG) {printf ("(% C, % d)", I + 'A', Y + 1); flag = 0 ;} else printf ("(% C, % d)", I + 'A', Y + 1); MX [I] = y; my [y] = I ;} mat [I] [Y] = 1;} If (! Flag) printf ("\ n"); else printf ("None \ n");} 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.