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 ...
随机推荐
- 新浪微博客户端(5)-自定义UISearchBar
iOS自带的UISearchBar有很多限制,我们可以使用UITextField做出一个类似于SearchBar的效果. //===================================== ...
- C语言strchr()函数:查找某字符在字符串中首次出现的位置
头文件:#include <string.h> strchr() 用来查找某字符在字符串中首次出现的位置,其原型为: char * strchr (const char *str, ...
- windows路径操作API函数
备用,方便查找: PathRemoveArgs 去除路径的参数 PathRemoveBackslash 去除路径最后的反斜杠"\" PathAddBackslash 在 ...
- android 利用View自身的setAnimation来实现动画
最近,在做一个程序要实现切换到下一项时要有动画的效果.使用ViewFlipper .TextSwitcher都没有办法达到效果,无意中发现TextView中有一个setAnimation的函数.调试了 ...
- [Effective JavaScript 笔记]第56条:避免不必要的状态
API有时被归为两类:有状态的和无状态的.无状态的API提供的函数或方法的行为只取决于输入,而与程序的状态改变无关.字符串的方法是无状态的.字符串的内容不能被修改,方法只取决于字符串的内容及传递给方法 ...
- Android Debugging
Debugging methods for Android Contents [hide] 1 Debuggers 1.1 Kernel and User co-debug with GDB on ...
- recv和send函数
转自 http://www.cnblogs.com/blankqdb/archive/2012/08/30/2663859.html 1. send解析 sockfd:指定发送端套接字描述符. bu ...
- 搭建CAS单点登录服务器
最近公司的一个项目需要用到单点登录的功能,之前对单点登录了解得不多.于是网上找了下单点登录的解决方案,发现CAS是个不错的解决方案.于是搭个环境测试了一下.这里记录下测试的详细步骤. 官网:http: ...
- MongoDB副本集学习(二):基本测试与应用
简单副本集测试 这一节主要对上一节搭建的副本集做一些简单的测试. 我们首先进入primary节点(37017),并向test.test集合里插入10W条数据: . rs0:PRIMARY> ;i ...
- codeforces B. Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/359/B 题目意思:给定n和k的值,需要构造一条长度为2n(每个元素取值范围只能是[1,2n])且元素各不 ...