[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) ...
随机推荐
- eclipse初始设置
1.界面显示设置 2.快捷创建的设置 window->Customize Perspective->Shortcuts 3.修改编码为utf-8 Preferences->Gener ...
- Redis实战(三)CentOS 7上Redis主从复制
一主二从架构 1.一主二从架构图 2.通过命令 mkdir redisCluster创建redis集群文件夹 3.通过命令mkdir 6380 mkdir 6381 mkdir 6382在re ...
- Druid.io启用SQL支持
Druid.io的SQL功能虽然在试验阶段,但是也支持了大部分的功能,而且还可以通过 Avatica JDBC查看请求的json,有助于我们理解Druid.io的语法.Druid.io有个比较坑的是, ...
- ubuntu 14.04安装JDK
As a workaround, you can install OpenJDK 8 from a PPA repository: 1. Open terminal from the Dash or ...
- 【codeforces】【比赛题解】#915 Educational CF Round 36
虽然最近打了很多场CF,也涨了很多分,但是好久没写CF的题解了. 前几次刚刚紫名的CF,太伤感情了,一下子就掉下来了,不懂你们Div.1. 珂学的那场我只做了第一题……悲伤. 这次的Education ...
- 【算法学习】有旋treap
treap是平衡树的一种.与其他平衡树一样,它也能够支持插入和删除,求第k极值等,接下来我们主要探讨有旋treap的实现过程. treap中每个节点要维护其值,左右孩子以及子树大小.父亲要不要写则看你 ...
- Ubuntu server 搭建Git server【转】
转自:http://www.cnblogs.com/candle806/p/4064610.html Ubuntu server 搭建Git server,git相比svn,最主要就是分布式了,每个客 ...
- Tomcat安装与优化
Tomcat安装与优化 1.安装jdk环境 最新的JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downlo ...
- linux服务器登录时慢出现卡顿
使用SSH远程登录Linux在输入用户名之后在过了好几秒之后才会出现输入密码.严重影响工作效率.登录很慢,登录上去后速度正常,这种情况的主要原因为: DNS反向解析的问题 SSH在登录的时候一般我们输 ...
- TableView 的那些坑
1. 分割线填满cell宽度, 并且设置分割线的颜色 1.1 利用系统的分割线填充 1.1.1 tableView 设置如下属性 // 给tableView设置如下属性值 tableView.layo ...