Evil

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

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

Description

Richard is evil. He wants to give another geometry problem to the participants of this contest and I’m afraid I have no choice but to comply. When asked why exactly he only could respond Richard Peng: for lulz So here’s what he wants you to do Richard Peng: find a circle that divides red into half Richard Peng: without taking any of the blue :D Fortunately our hero, Mark, has managed to change that 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 be parallel to the x and y axis. There will always be a positive even number of red points. No two points will be at the same position. For the purposes of this problem you can assume that a rectangle contains all points on its border and interior.

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=;
#define mod 1000000009
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int n;
int num1,num2;
struct node
{
int x,y;
};
node a[];
node b[];
int ans;
bool ok(int x,int xx,int y,int yy)
{
for(int i=;i<num2;i++)
if(b[i].x<=x&&b[i].x>=xx&&b[i].y<=y&&b[i].y>=yy)
return ;
return ;
} void dfs(int t,int pre,int xmax,int xmin,int ymax,int ymin)
{
if(t>=num1/)
{
if(ok(xmax,xmin,ymax,ymin))
ans=min(ans,(xmax-xmin)*(ymax-ymin));
return;
}
for(int i=pre+;i<num1;i++)
dfs(t+,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=;
while(cin>>n)
{
if(n==)
break;
ans=inf;
num1=num2=;
for(int i=;i<n;i++)
{
int x=read(),y=read(),z=read();
if(z==)
a[num1].x=x,a[num1++].y=y;
else
b[num2].x=x,b[num2++].y=y;
}
dfs(,-,-inf,inf,-inf,inf);
if(ans!=inf)
printf("Case %d: %d\n",t++,ans);
else
printf("Case %d: -1\n",t++);
}
}

Codeforces Gym 100463D Evil DFS的更多相关文章

  1. Gym 100463D Evil DFS

    Evil Time Limit: 5 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descri ...

  2. Codeforces Gym 100650B Countdown DFS

    Problem B: CountdownTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/conte ...

  3. CF Gym 100463D Evil (二维前缀和+离散)

    题意:给一些带颜色的点,求一个最小的矩形,恰好包括一半的红色点,且不包括蓝色点. 题解:暴力,求个二维前缀和,用容斥原理更新一下.N很小所以我采用了离散优化,跑了个0ms. 之前没写过二维前缀和,加上 ...

  4. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  5. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  6. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  7. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  8. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  9. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

随机推荐

  1. SoapUI中Groovy的实用方法

    1.依照上次结果判断下步是否执行: import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus myTestStep ...

  2. 14个最受欢迎的Python开源框架

    本文从GitHub中整理出的14个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框架 Dja ...

  3. PHPSTORM 与 Xdebug 配合调试

    基本的配置可以参考网上的文档, 浏览器中装插件(xdebug)或直接在请求中加上如下的参数也可启动调试 ?XDEBUG_SESSION_START=PHPSTORM

  4. 二叉树单色路径最长&amp;&amp;穿珠子

    对树的操作,特别理解递归的好处. //对于一棵由黑白点组成的二叉树,我们需要找到其中最长的单色简单路径,其中简单路径的定义是从树上的某点开始沿树边走不重复的点到树上的 //另一点结束而形成的路径,而路 ...

  5. Ubuntu上用快捷键关闭没有响应的程序

    Linux 上有很多方法可以强制关闭无响应的程序,比如你可以通过按快捷键 Ctrl + Shift + T 来调出 Terminal 或者用 Ctrl + Shift + F1 进入 Console ...

  6. 更改VS的运行主窗体

    Program.cs中Application.EnableVisualStyles();              Application.SetCompatibleTextRenderingDefa ...

  7. SSO单点登录在web上的关键点 cookie跨域

    概述 其实WEB单点登录的原理挺简单的,抛开那些复杂的概念,简单来讲讲如何实现一个最基本的单点登录 首先需要有两个程序 例如:http://www.site-a.com 我们简称A http://ww ...

  8. Hadoop 问题 & 解决

    1.将旧版本hadoop升级后,如从hadoop-1.1.2升级到hadoop-1.2.1,会发现使用start-all.sh命令,没有办法启动namenode,即jps,发现没有namenode 原 ...

  9. HDOJ-ACM1009(JAVA) (传说中的贪心算法)分为数组实现 和 封装类实现

    转载声明:原文转自:http://www.cnblogs.com/xiezie/p/5564311.html 这个道题有几点要注意的: 数组存放的类型:float或double 打印的格式:(如果只是 ...

  10. cocos中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)

    CCLabelTTF CCLabelTTF 每次调用 setString (即改变文字)的时候,一个新的OPENGL 纹理将会被创建..这意味着setString 和创建一个新的标签一样慢. 这个类使 ...