Evil
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100463/attachments
Description
Input
There are several test cases in each input file. The first line of each 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 the 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 above. 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
题意
给你一个坐标系,上面有n个点,要求找到一个矩形,使得能够框住一半的红点,不框进任何一个蓝点,求最小矩形面积
题解:
暴力枚举就好了,注意,矩形面积可以为0
代码
#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> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) const int maxn=2501; #define mod 1000000009 #define eps 1e-9 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } //************************************************************************************** int n; int num1,num2; struct node { int x,y; }; node a[40]; node b[40]; int ans; bool ok(int x,int xx,int y,int yy) { for(int i=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; } void dfs(int t,int pre,int xmax,int xmin,int ymax,int ymin) { if(t>=num1/2) { if(ok(xmax,xmin,ymax,ymin)) ans=min(ans,(xmax-xmin)*(ymax-ymin)); return; } for(int i=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)); } int main() { int t=1; while(cin>>n) { if(n==0) break; ans=inf; num1=num2=0; for(int i=0;i<n;i++) { int x=read(),y=read(),z=read(); if(z==0) a[num1].x=x,a[num1++].y=y; else b[num2].x=x,b[num2++].y=y; } dfs(0,-1,-inf,inf,-inf,inf); if(ans!=inf) printf("Case %d: %d ",t++,ans); else printf("Case %d: -1 ",t++); } }