Gym 100463D Evil DFS

Source: Internet
Author: User

Time Limit:5 Sec

Memory limit:256 MB

Topic Connection

Http://codeforces.com/gym/100463/attachments

Descriptionrichard is evil. He wants to give another geometry problem to the participants of this contest and I ' M afraid I had no choice but to compl Y. When asked why exactly he is only could respond Richard peng:for lulz So here's what he wants and do Richard Peng:fin D a circle that divides red to half Richard Peng:without taking any of the blue:D Fortunately our hero, Mark, have managed to the change of the circle to an axis parallel rectangle. Given a set of points in the plane each colored red or blue, find the area of the smallest rectangle that contains exactly Half of the red points and none of the blue. The rectangle ' s sides should is parallel to the x and Y axis. There'll always be a positive even number of red points. No. Points'll is at the same position. For the purposes of this problem you can assume, a rectangle contains all points on its border and interior.

Input

There is several test cases in each input file. The first line of all test case contains N (2≤N≤20), the number of points. The following N lines contain XI, Yi, and ci (−1000≤xi, Yi, ≤1000, 0≤ci≤1) giving the x and y coordinates of TH e ith point. The ith point is red if CI = 0 and blue if CI = 1. The last line of input contains a zero.

Output

For each test case output the case number followed by the area of the smallest rectangle that satisfies the conditions ABO Ve. If it is impossible output-1 instead. Follow the format in the sample output.

Sample Input

7-10 0 0-1 0 0 1 0 0 10 0 0-1-1 0 1 1 0 0 0 1 7-4 0 0-2 0 0 2 0 0 4 0 0-3 0 1 0 0 1 3 0 1 0

Sample Output

Case 1:9 Case 2:1

HINT

Test instructions

Give you a coordinate system with n dots on it, asking for a rectangle to be able to frame half of the red dots, not to frame any of the blue dots, to find the smallest rectangular area

Exercises

Dfs

Code

1#include <cstdio>2#include <cmath>3#include <cstring>4#include <ctime>5#include <iostream>6#include <algorithm>7#include <Set>8#include <vector>9#include <queue>Ten#include <map> One#include <stack> A #defineINF 1000000007 - #defineMAXN 32001 - using namespacestd; the typedef __int64 LL; - inline ll read () - { -ll x=0, f=1; +     CharCh=GetChar (); -      while(ch<'0'|| Ch>'9') +     { A         if(ch=='-') f=-1; atCh=GetChar (); -     } -      while(ch>='0'&&ch<='9') -     { -x=x*Ten+ch-'0'; -Ch=GetChar (); in     } -     returnx*F; to } + //******************************************************************* -  the structSS * { $     intx, y;Panax Notoginseng} a[ -],b[ -]; - BOOLCMP (ss S1,ss S2) the { +     if(s1.x!=s2.x) A         returns1.x<s2.x; the     Else returns1.y<s2.y; + } - intn,m; $ BOOLJugintUpintDownintLintR) $ { -      for(intI=1; i<=m; i++) -     { the         if((r>=b[i].x&&b[i].x>=l) && (up>=b[i].y&&b[i].y>=Down )) -             return false;Wuyi     } the     return true; - } Wu intN; - intans; About voidDfsintXintKintUpintDownintLintR) $ { -     if(k==n/2+n%2) -     { -Ans=min (ABS (R-L) *abs (up-Down ), ans); A         return ; +     } the      for(inti=x+1; i<=n; i++) -     { $         intups=Max (a[i].y,up); the         intdowns=min (a[i].y,down); the         intls=min (l,a[i].x); the         intrs=Max (r,a[i].x); the         if(Jug (ups,downs,ls,rs)) -DFS (i,k+1, ups,downs,ls,rs); in     } the } the intMain () About { the     intoo=1; the  the      while(SCANF ("%d", &n)! =EOF) +     { -ans=inf; the         if(n==0) Break;Bayin=0; them=0; the         intX,y,ch; -          for(intI=1; i<=n; i++) -         { thex=read (); they=read (); theCh=read (); the             if(ch==0) -             { thea[++n].x=x; thea[n].y=y; the             }94             Else the             { theb[++m].x=x; theb[m].y=y;98             } About         } -Sort (A +1, a+n+1, CMP);101Sort (b +1, b+m+1, CMP);102         103Dfs0,0,-inf,inf,inf,-inf);104printf"Case %d:", oo++); the         if(ans==inf)106         {107printf"-1\n");108         }109         Elseprintf"%d\n", ans); the     }111     return 0; the}
View Code

Gym 100463D Evil DFS

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.