Gym 100463D Evil DFS
Evil
Time Limit: 5 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个点,要求找到一个矩形,使得能够框住一半的红点,不框进任何一个蓝点,求最小矩形面积
题解:
dfs
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define inf 1000000007
#define maxn 32001
using namespace std;
typedef __int64 ll;
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;
}
//******************************************************************* struct ss
{
int x,y;
} a[],b[];
bool cmp(ss s1,ss s2)
{
if(s1.x!=s2.x)
return s1.x<s2.x;
else return s1.y<s2.y;
}
int N,M;
bool jug(int up,int down,int l,int r)
{
for(int i=; i<=M; i++)
{
if((r>=b[i].x&&b[i].x>=l)&&(up>=b[i].y&&b[i].y>=down))
return false;
}
return true;
}
int n;
int ans;
void dfs(int x,int k,int up,int down,int l,int r)
{
if(k==N/+N%)
{
ans=min(abs(r-l)*abs(up-down),ans);
return ;
}
for(int i=x+; i<=N; i++)
{
int ups=max(a[i].y,up);
int downs=min(a[i].y,down);
int ls=min(l,a[i].x);
int rs=max(r,a[i].x);
if(jug(ups,downs,ls,rs))
dfs(i,k+,ups,downs,ls,rs);
}
}
int main()
{
int oo=; while(scanf("%d",&n)!=EOF)
{
ans=inf;
if(n==) break;
N=;
M=;
int x,y,ch;
for(int i=; i<=n; i++)
{
x=read();
y=read();
ch=read();
if(ch==)
{
a[++N].x=x;
a[N].y=y;
}
else
{
b[++M].x=x;
b[M].y=y;
}
}
sort(a+,a+N+,cmp);
sort(b+,b+M+,cmp); dfs(,,-inf,inf,inf,-inf);
printf("Case %d: ",oo++);
if(ans==inf)
{
printf("-1\n");
}
else printf("%d\n",ans);
}
return ;
}
Gym 100463D Evil DFS的更多相关文章
- Codeforces Gym 100463D Evil DFS
Evil Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Descr ...
- CF Gym 100463D Evil (二维前缀和+离散)
题意:给一些带颜色的点,求一个最小的矩形,恰好包括一半的红色点,且不包括蓝色点. 题解:暴力,求个二维前缀和,用容斥原理更新一下.N很小所以我采用了离散优化,跑了个0ms. 之前没写过二维前缀和,加上 ...
- Gym 102346A Artwork dfs
Artwork Gym - 102346A 题意:给n*m的地图,入口是(0,0),出口是(n,m),其中有k个监视器,坐标是(xi,yi),监视半径是r,问一个人能不能不被监视到,从起点到终点. 如 ...
- Artwork (Gym - 102346A)【DFS、连通块】
Artwork (Gym - 102346A) 题目链接 算法 DFS,连通块 时间复杂度:O(k*n + k * k) 1.这道题就是让你判断从(0,0)到(m,n),避开中途所有的传感器(传感器的 ...
- Codeforces Gym 100650B Countdown DFS
Problem B: CountdownTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/conte ...
- Tourists Gym - 101002I LCA——dfs+RMQ在线算法
LCA(Least Common Ancestors),即最近公共祖先,是指这样一个问题:在有根树中,找出某两个结点u和v最近的公共祖先(另一种说法,离树根最远的公共祖先). 知识需求:1)RMQ的S ...
- UVaLive 6950 && Gym 100299K Digraphs (DFS找环或者是找最长链)
题意:有n个只包含两个字母的字符串, 要求构造一个m*m的字母矩阵, 使得矩阵的每行每列都不包含所给的字符串, m要尽量大, 如果大于20的话构造20*20的矩阵就行了. 析:开始吧,并没有读对题意, ...
- L - The Shortest Path Gym - 101498L (dfs式spfa判断负环)
题目链接:https://cn.vjudge.net/contest/283066#problem/L 题目大意:T组测试样例,n个点,m条边,每一条边的信息是起点,终点,边权.问你是不是存在负环,如 ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
随机推荐
- Linux rpm 命令参数使用详解[介绍和应用](转)
RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序” rpm 执行安装包二进制包(Binary)以及源代码包(Source)两种 ...
- explicit构造函数
explicit构造函数 Explicit Constructors(显式构造函数)收藏 按照默认规定,只有一个参数的构造函数也定义了一个隐式转换,将该构造函数对应数据类型的数据转换为该类对象,如下面 ...
- iOS工程如何支持64-bit(转)
苹果在2014年10月20号发布了一条消息:从明年的二月一号开始,提交到App Store的应用必须支持64-bit.详细消息地址为:https://developer.apple.com/news/ ...
- 简单实现Tab切换(带框架)
<script type="text/javascript"> $(function () { //加载时添加的标签卡 if ('<%=Request[" ...
- git参考资料
个人博客 http://www.iwangzheng.com/ $git log --graph $git reset --hard 67889898... $ssh-add $git pull -- ...
- C++中的vector使用范例
原文链接 http://blog.csdn.net/tjh666/article/details/1604119 1.vector 的数据的存入和输出: #include<stdio.h> ...
- stringbuffer 和 stringbuilder的区别
1. stringbuffer 和 stringbuilder的区别 StringBuffer是线程安全的, 这个类里的所有方法是同步的.这个反过来就会对程序的性能有一定的影响.StringBuild ...
- poj 3026 bfs+prim Borg Maze
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9718 Accepted: 3263 Description The B ...
- ubuntu上完全卸载package
inux上完整的卸载apt方式安装软件的办法. 假设你的包叫做: your_pkg apt-get --purge remove your_pkg apt-get autoremove apt-get ...
- apache2:Invalid option to WSGI daemon process definition
版本说明: ubuntu 12.04 server /apache 2.2 / mod_wsgi 3.3 / python 2.7.3 /django 1.7 在ubuntu12的服务器上配置djan ...