[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) ...
随机推荐
- Redis学习八:Redis的事务
一.是什么 可以一次执行多个命令,本质是一组命令的集合.一个事务中的所有命令都会序列化,按顺序地串行化执行而不会被其它命令插入,不许加塞. 二.能干嘛 一个队列中,一次性.顺序性.排他性的执行一系列命 ...
- Swift动态添加UIImageView并添加事件
Swift动态添加UIImageView并添加事件: 1. 创建UIImageView实例,并进行初始化 2. 设置UIImageView的用户交互属性userInteractionEnabled为T ...
- python json dumps loads
请看以上图片可知 1. python requests里面返回的是json 字符串, 说白了是字符串.不能直接取里面对应的值. 2. 取值的话,需要把json字符串转换成字典, 用json.loads ...
- Eclipse改变相同代码高亮颜色
一.点击某一代码时,让相同代码高亮显示(Eclipse默认是这样的) Window ->preferences ->Java ->Editor ->Mark Occurrenc ...
- NameValuePair方式传参数
今天工作中联调外部的一个接口用post方式传输,我按照文档封装参数成Jason字符串传入,但是对方一直接受参数为空,折腾了半天也没找到问题.很苦恼,检查代码都没有错误,可是为什么对方接受参数为空呢?然 ...
- flask配置日志输出文件
1.flask可以通过日志库来指点日志输出的路径, 配置日志输出的连接:www.gaodin.com
- vue-cli环境搭建初探!
1.先安装nodejs环境 https://npm.taobao.org/mirrors/node (选择版本) 下一步 下一步 默认安装就行 2.检查node和npm的是否成功安装 node -v ...
- 20165230 2017-2018-2 《Java程序设计》第9周学习总结
20165230 2017-2018-2 <Java程序设计>第9周学习总结 教材学习内容总结 第十二章 java网络编程 学习了用于网络编程的类,了解URL.Socket.InetAdd ...
- 关于runOnUiThread()与Handler两种更新UI的方法
在Android开发过程中,常需要更新界面的UI.而更新UI是要主线程来更新的,即UI线程更新.如果在主线线程之外的线程中直接更新页面显示常会报错.抛出异常:android.view.ViewRoot ...
- docker制作镜像步骤
一.查看宿主机下是否有符合需求的docker镜像 操作命令如下: [root@server4 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZ ...