CF #330 D2 E
相当于给你一些点,要你最多删除不超过k,使得能使用一个边长为整数的长方形,与XY轴平行,使长方形的面积最小。
上课时拿笔来画画,然后忽然思路就开了,要是比赛也这样就好了~~先按X,Y分别排序,由于K较小,而且,删除的时候肯定会删除最外围的点,所以,可以上下左右枚举删了哪些点,排序后的数组来模拟这个过程,最多4^K个选择,可以过。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std; ///vector<int>f;
const int MAX=100050; struct Point{
double x,y;
int index;
}ptx[MAX],pty[MAX]; bool cmpx(Point a,Point b){
if(a.x<b.x) return true;
return false;
} bool cmpy(Point a,Point b){
if(a.y<b.y) return true;
return false;
}
bool vis[MAX]; int n,k;
LL ans; void dfs(int wl,int wr,int hl,int hr,int counts){
if(!counts){
while(vis[ptx[wl+1].index]) wl++;
while(vis[ptx[wr-1].index]) wr--;
while(vis[pty[hl+1].index]) hl++;
while(vis[pty[hr-1].index]) hr--;
LL x=(ptx[wr-1].x-ptx[wl+1].x==0)?1:(LL)(ptx[wr-1].x-ptx[wl+1].x+0.5);
LL y=(pty[hr-1].y-pty[hl+1].y==0)?1:(LL)(pty[hr-1].y-pty[hl+1].y+0.5);
ans=min(ans,x*y);
return ;
} for(int i=wl+1;;i++){
if(vis[ptx[i].index]) continue;
vis[ptx[i].index]=true;
dfs(i,wr,hl,hr,counts-1);
vis[ptx[i].index]=false;
break;
}
for(int i=wr-1;;i--){
if(vis[ptx[i].index]) continue;
vis[ptx[i].index]=true;
dfs(wl,i,hl,hr,counts-1);
vis[ptx[i].index]=false;
break;
}
for(int i=hl+1;;i++){
if(vis[pty[i].index]) continue;
vis[pty[i].index]=true;
dfs(wl,wr,i,hr,counts-1);
vis[pty[i].index]=false;
break;
}
for(int i=hr-1;;i--){
if(vis[pty[i].index]) continue;
vis[pty[i].index]=true;
dfs(wl,wr,hl,i,counts-1);
vis[pty[i].index]=false;
break;
} } int main(){
while(scanf("%d%d",&n,&k)!=EOF){
double x1,y1,x2,y2;
for(int i=0;i<n;i++){
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
ptx[i].x=(x1+x2)/2;ptx[i].y=(y1+y2)/2;
ptx[i].index=i;
pty[i]=ptx[i];
vis[i]=false;
}
sort(ptx,ptx+n,cmpx);
sort(pty,pty+n,cmpy);
ans=(1LL<<62);
if(k==n-1){
cout<<1<<endl;
continue;
}
dfs(-1,n,-1,n,k);
cout<<ans<<endl;
} }
CF #330 D2 E的更多相关文章
- CF#310 d2
A:|c[1]-c[0]| B:A+-(oc)A[0]==0..n-1 C: #include <cstdio> int n,m,i,j,k,p; int ll,ca,cb,cc; int ...
- CF # 369 D2 D、E
D,只要抓住每个点只有一个出度,那么图就能分成几个部分,而且可以发现,一个部分最多一个环. #include <iostream> #include <cstdio> #inc ...
- CF# 368 D2 D
很容易想到可以它操作序列弄成有向图,果断深搜.但我开始竟然用了一种特醇的方法,每个书架做一次深搜,复杂度O(nq),跑到57个test就不动了.看看代码吧 #include <iostream& ...
- CF #330 C
改了题目之后,就是没有奇数的测试了... 其实可以很轻易地发现,要距离近的一方只会删除两端的,而要求远的一方会删除中间的. 那么,很明显的,剩下的两点会相差x/2个节点,于是,只要计算i和i+x/2的 ...
- NSCharacterSet 使用说明
NSCharacterSet 和 NSMutableCharacterSet 用面向对象的方式来表示一组Unicode字符,它经常与NSString及NSScanner组合起来使用,在不同的字符上 ...
- ssl
在Java加密技术(八)中,我们模拟了一个基于RSA非对称加密网络的安全通信.现在我们深度了解一下现有的安全网络通信--SSL. 我们需要构建一个由CA机构签发的有效证书,这里我们使用上文中生 ...
- Visual Studio 2015的坑:中文字符串编译后成乱码
(2015年8月5日更新:微软已经修复了Roslyn的这个bug,详见 https://github.com/dotnet/roslyn/pull/4303 ) 昨天,我们用VS2015编译了博客程序 ...
- LayaAir引擎——(九)
var h = new Array(); var j = new Array(); var xbCursor = 0; function xbinit() { xbinitName(); xbRect ...
- MIM协议与Base64编码
MIME Protocol 1. MIME的全称是"Multipurpose Internet Mail Extensions",中译为"多用途互联网邮件扩展" ...
随机推荐
- C 语言程序员必读的 5 本书,你读过几本?
你正通过看书来学习C语言吗?书籍是知识的丰富来源.你可以从书中学到各种知识.书籍可以毫无歧视地向读者传达作者的本意.C语言是由 Dennis Ritchie在1969年到1973年在贝尔实验室研发的. ...
- JavaScript学习四
2019-06-01 09:09:23 坚持,加油!!! 函数的学习 <html> <head> <script type="text/javascript&q ...
- SQLServer局部变量和全局变量介绍05-29学习笔记
变量 数据在内存中存储可以变化的量叫变量.为了在内存中存储信息,用户必须指定存储信息的单元,并为了该存储单元命名, 以方便获取信息,这就是变量的功能.Transact-SQL可以使用两种变量,一种是局 ...
- 题解报告:hdu 2149 Public Sale(巴什博弈)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=2149 Problem Description 虽然不想,但是现实总归是现实,Lele始终没有逃过退学的命运,因为他没 ...
- Objective-C——关联对象
动态语言 OC是一种动态语言,它的方法,对象的类型都是到运行的时候才能够确定的.所以这就使得OC存在了关联对象这一强大的机制. 关联对象 所谓关联对象,其实就是我们在运行时对一个已存在的对象上面绑定一 ...
- Laravel5.1学习笔记16 数据库2 查询构造器(这个不用看,不如用EloquentORM)
Introduction Retrieving Results Aggregates Selects Joins Unions Where Clauses Advanced Where Clauses ...
- [Android]异常8-android.view.WindowManager$BadTokenException
背景:Service服务中使用WindowManager时,Android4.4使用正常,Android6.0使用应用崩溃停止运行,提示android.view.WindowManager$BadTo ...
- 【VHDL】组合逻辑电路和时序逻辑电路的区别
简单的说,组合电路,没有时钟:时序电路,有时钟. ↓ 也就是说,组合逻辑电路没有记忆功能,而时序电路具有记忆功能. ↓ 在VHDL语言中,不完整条件语句对他们二者的影响分别是什么?组合逻辑中可能生成锁 ...
- nagios 安装pnp4nagios插件
Naigos install pnp4nagios 绘图插件 原文地址:http://www.cnblogs.com/caoguo/p/5022230.html [root@Cagios ~]# yu ...
- Centos7 Openstack - (第二节)添加认证服务(Keystone)
Centos7 install Openstack - (第二节)添加认证服务(Keystone) 我的blog地址:http://www.cnblogs.com/caoguo 根据openstack ...