Codeforces Gym 100463D Evil DFS

Source: Internet
Author: User

Time Limit:20 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

Violent enumeration just fine, notice that the rectangular area can be 0

Code

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=2501;#defineMoD 1000000009#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************intN;intnum1,num2;structnode{intx, y;}; Node a[ +];node b[ +];intans;BOOLOkintXintXxintYintyy) {     for(intI=0; i<num2;i++)        if(b[i].x<=x&&b[i].x>=xx&&b[i].y<=y&&b[i].y>=yy)return 0; return 1;}voidDfsintTintPreintXmax,intXminintYmaxintymin) {    if(t>=num1/2)    {        if(OK (xmax,xmin,ymax,ymin)) ans=min (ans, (xmax-xmin) * (ymax-ymin)); return; }     for(intI=pre+1; i<num1;i++) DFS (t+1, I,max (A[i].x,xmax), Min (xmin,a[i].x), Max (ymax,a[i].y), Min (ymin,a[i].y));}intMain () {intt=1;  while(cin>>N) {if(n==0)             Break; Ans=inf; NUM1=num2=0;  for(intI=0; i<n;i++)        {            intX=read (), Y=read (), z=read (); if(z==0) a[num1].x=x,a[num1++].y=y; Elseb[num2].x=x,b[num2++].y=y; } DFS (0,-1,-inf,inf,-Inf,inf); if(ans!=inf) printf ("Case %d:%d\n", t++, ans); Elseprintf ("Case %d: -1\n", t++); }}

Codeforces 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.