[HDU - 5408] CRB and Farm
题意:
给出一个由n个点组成的凸包,以及凸包内的k个点,问是否能够在凸包上选择最多2k个点构造一个新的
凸包,使得新的凸包覆盖原来的k个点。
要求2k个点覆盖原本的k个点,只要对原k个点构造凸包,然后选择该凸包内一点O与该凸包的顶点连一条射线,其
与大凸包相交的边的两端点即为要保留的点,小凸包的顶点个数<=k,所有结果最后一定存在。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-7
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e9+9
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
double ox,oy;
struct Point{
double x,y,id;
Point(){}
Point(double x,double y):x(x),y(y) {}
bool operator < (const Point &a)const { if(x==a.x) return y<a.y; return x<a.x; }
Point operator - (const Point &a)const{ return Point(x-a.x,y-a.y); }
Point operator + (const Point &a)const{ return Point(x+a.x,y+a.y); }
Point operator * (const double &a)const{ return Point(x*a,y*a); }
Point operator / (const double &a)const{ return Point(x/a,y/a); }
void read(){ scanf("%lf%lf",&x,&y); }
bool operator == (const Point &a)const{ return dcmp(x-a.x)== && dcmp(y-a.y)==; }
};
double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y; }
ll dis(Vector a) { return sqrt(Dot(a,a)); }
double Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; }
int ConvexHull(Point *p,int n,Point *ch){
sort(p+,p++n);
int m=;
For(i,,n){
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
Fore(i,n-,) {
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
}
Point getInsect(Point p,Vector v,Point q,Vector w) {
Vector u=p-q;
double t=Cross(w,u)/Cross(v,w);
return p+v*t;
}
Point p[],pp[],ch[],o;
bool chk(Point p1,Point p2,Point q1,Point q2) {
double c1=Cross(p2-p1,q1-p1),c2=Cross(p2-p1,q2-p1);
double c3=Dot(p2-p1,q1-p1),c4=Dot(p2-p1,q2-p1);
if(dcmp(c1)*dcmp(c2)<) {
Point cp=getInsect(p1,p2-p1,q1,q2-q1);
return Dot(cp-p1,p2-p1)>;
}
return ;
}
int n,k,res;
set<int>ans;
void solve(){
ans.clear();
scanf("%d",&n);
For(i,,n-) p[i].read();
scanf("%d",&k);
For(i,,k) pp[i].read();
int m=ConvexHull(pp,k,ch);
o=ch[];
For(i,,m-) o=(o+ch[i])/;
res=;
For(i,,m-) {
while(!chk(o,ch[i],p[res],p[(res+)%n])) res=(res+)%n;
ans.insert(res);ans.insert((res+)%n);
}
set<int>::iterator it;
cout<<"Yes"<<endl;
cout<<ans.sz<<endl;
for(it=ans.begin();it!=ans.end();it++){
if(it!=ans.begin()) printf(" ");
printf("%d",(*it)+);
}
cout<<endl;
}
int main(){
// fre("in.txt","r",stdin);
int t=;
cin>>t;
For(i,,t) solve();
return ;
}
[HDU - 5408] CRB and Farm的更多相关文章
- Hdu 5416 CRB and Tree (bfs)
题目链接: Hdu 5416 CRB and Tree 题目描述: 给一棵树有n个节点,树上的每条边都有一个权值.f(u,v)代表从u到v路径上所有边权的异或值,问满足f(u,v)==m的(u, v) ...
- Hdu 5407 CRB and Candies (找规律)
题目链接: Hdu 5407 CRB and Candies 题目描述: 给出一个数n,求lcm(C(n,0),C[n,1],C[n-2]......C[n][n-2],C[n][n-1],C[n][ ...
- HDU 5416 CRB and Tree(前缀思想+DFS)
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- hdu 5412 CRB and Queries
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5412 CRB and Queries Description There are $N$ boys i ...
- HDU 5412 CRB and Queries(区间第K大 树套树 按值建树)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5412 Problem Description There are N boys in CodeLan ...
- HDU 5410 CRB and His Birthday(完全背包变形)
CRB and His Birthday Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 5410 CRB and His Birthday(混合背包)
Problem Description Today is CRB's birthday. His mom decided to buy many presents for her lovely son ...
- HDU 5412 CRB and Queries 动态整体二分
Problem Description There are N boys in CodeLand.Boy i has his coding skill Ai.CRB wants to know who ...
- HDU - 5413 CRB and Roads
CRB and Roads Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- 权限 mock location
1.集成环信的时候,该权限报错: mock location权限是是“允许程序创建模拟位置”,主要是提供用于测试.打包的时候并不需要,所以解决办法分两步: 1.声明tools 2.添加忽略:
- uploadify IE11 不兼容问题(不显示图片)
1.进入uploadify官网demo : http://www.uploadify.com/demos/ 2. 显示 (确认flash为最新版本) 3.更换其它浏览器一切正常 4.原因:I ...
- UC手机浏览器(U3内核)相关文档整理
Note:绝大多数API在IOS版下不支持,使用前请自行测试. UC官方的开发者中心:http://www.uc.cn/business/developer.shtml U3内核定制<meta& ...
- [问题]通过IIS宿主发布WCF服务,客户端添加服务引用出错的解决办法
环境配置:Web服务器:Windows Server 2008,iis7.5,.net4.0客户端:XPsp3 vs2010 sp1 问题描述:1.确定WCF服务访问地址 http://servic ...
- 悲催的IE6 七宗罪大吐槽(带解决方法)第一部分
一.奇数宽高 悲剧的IE6啊,为何有如此多bug,但用户市场又那么大,真让我们搞网站的纠结.今天就遇到了一个非常奇怪但又很细节的一个bug,一个外部的相对定位div,内部一个绝对定位的div(righ ...
- 20155224 2016-2017-2 《Java程序设计》第7周学习总结
20155224 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 第十二章 标准API的函数接口 Consumer接口:接受一个自变量,处理不返回值. Fun ...
- 【转】WPF的知识
[-] 闲话WPF之二XAML概述 闲话WPF之五XAML中的类型转换 闲话WPF之十六WPF中的资源 2 闲话WPF之十九WPF中的传递事件 1 闲话WPF之二十WPF中的传递事件 2 闲话WPF之 ...
- 【leetcode 简单】 第五十九题 同构字符串
给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的. 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不能映射到同一 ...
- Web 前端开发规范文档
通用规范: TAB键用两个空格代替(WINDOWS下TAB键占四个空格,LINUX下TAB键占八个空格). CSS样式属性或者JAVASCRIPT代码后加“;”方便压缩工具“断句”. 文件内容编码均统 ...
- 渗透测试===kali linux的安装
方法一: kali linux 安装在本地的vitural box 或者 wm ware中 方法二: 安装在移动硬盘或者储存卡中,插到电脑就能用