[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) ...
随机推荐
- CSS3实战之resize
resize属性可以设置是否允许用户缩放网页中元素的大小 总共有4种取值 none vertical horizontal both 举个栗子 <!DOCTYPE html PUBLIC &qu ...
- Git Cannot rebase: You have unstaged changes.
Cannot rebase: You have unstaged changes. 那说明你有修改过的文件git stashgit pull --rebase (每次push之前最好这样做一次)git ...
- nginx反向代理下没有获取到正确的clientIP问题发散
问题背景: 在使用nginx服务器NginxA 来反向代理服务 WebAPIA,WebAPIA中要获取ClientIP,结果获取到的IP为NginxA的, 于是引出了以下的一连串概念... 首先使用X ...
- 双11怎么那么强!之二:浅析淘宝网络通信库tbnet的实现
最近开始看Tair的源码实现,Tair的通信使用的是淘宝的开源的网络库tbnet实现.具体来说是依靠tbnet::Transport类型实现,其源代码路径如下:http://code.taobao.o ...
- C语言编写守护进程
概念 守护进程(daemon)是一种运行在后台的一种特殊的进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.由于在Linux中,每个系统与用户进行交流的界面成为终端,每一个从此终 ...
- 2016.5.16——leetcode:Rotate Array,Factorial Trailing Zeroe
Rotate Array 本题目收获: 题目: Rotate an array of n elements to the right by k steps. For example, with n = ...
- 【比赛游记】NOIWC2019冬眠记
上接THUWC2019酱油记. 贴一点文艺汇演的精彩表演: https://www.bilibili.com/video/av42089198/ https://www.bilibili.com/vi ...
- XSS练习小游戏和答案参考
源码:https://files.cnblogs.com/files/Eleven-Liu/xss%E7%BB%83%E4%B9%A0%E5%B0%8F%E6%B8%B8%E6%88%8F.zip 感 ...
- oracle用plsql查询死锁
1. 点击plsql 工具(tool),点击会话(session) 2.点击锁,可以看到锁的session
- 16 Go Concurrency Patterns: Timing out, moving on GO并发模式: 超时, 继续前进
Go Concurrency Patterns: Timing out, moving on GO并发模式: 超时, 继续前进 23 September 2010 Concurrent progra ...