zoukankan      html  css  js  c++  java
  • 【POJ1912】【Ceoi2002】—A highway and the seven dwarfs(凸包)

    传送门

    题意:给出平面上的 nn 个点,对于 mm 条直线,依次判断这 nn 个点是否在每条直线的同一侧。(n,m105n,m≤10^5)

    考虑对于每一条直线,显然我们要找到凸包上距离这条直线最远的2个点,判一下方向

    考虑到类似于旋转卡壳对踵的的思想
    记录一下每条边的斜率,然后二分找到的就是最远的点了

    #include<bits/stdc++.h>
    using namespace std;
    inline int read(){
    	char ch=getchar();
    	int res=0,f=1;
    	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    	while(isdigit(ch))res=res*10+(ch^48),ch=getchar();
    	return res*f;
    }
    const int N=100005;
    const double pi=acos(-1);
    const double eps=1e-8;
    struct point{
    	double x,y;
    	point(double a=0,double b=0){
    		x=a,y=b;
    	}
    	friend inline point operator +(const point &a,const point &b){
    		return point(a.x+b.x,a.y+b.y);
    	}
    	friend inline point operator -(const point &a,const point &b){
    		return point(a.x-b.x,a.y-b.y);
    	}
    	friend inline double operator *(const point &a,const point &b){
    		return (a.x*b.y-a.y*b.x);
    	}
    	inline int calc(){
    		return x*x+y*y;
    	}
    }p[N],q[N],a,b;
    int n,top;
    double af[N];
    inline bool comp(const point &a,const point &b){
    	double res=(a-p[1])*(b-p[1]);
    	return (res==0)?((a-p[1]).calc()<(b-p[1]).calc()):(res>0);
    }
    inline void graham(){
    	int idx=1;
    	for(int i=2;i<=n;i++){
    		if(p[idx].y<p[i].y||(p[idx].y==p[i].y&&p[i].x<p[idx].x))
    		idx=i;
    	}
    	if(idx!=1)swap(p[idx],p[1]);
    	sort(p+2,p+n+1,comp);
    	q[++top]=p[1];
    	for(int i=2;i<=n;++i){
    		while(top>=3&&((p[i]-q[top-1])*(q[top]-q[top-1])>=0))
    			top--;
    		q[++top]=p[i];
    	}
    	q[top+1]=q[1];
    	for(int i=1;i<=top;i++)
    		af[i]=atan2(q[i+1].y-q[i].y,q[i+1].x-q[i].x);
    }
    int main(){
    	n=read();
    	for(int i=1;i<=n;i++){
    		scanf("%lf%lf",&p[i].x,&p[i].y);
    	}
    	if(n>1)graham();
    	while(scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y)!=EOF){
    		if(n==1){
    			cout<<"GOOD"<<'
    ';continue;
    		}
    		double l1=atan2(b.y-a.y,b.x-a.x),l2=atan2(a.y-b.y,a.x-b.x);
    		int pos1=lower_bound(af+1,af+top+1,l1)-af;
    		int pos2=lower_bound(af+1,af+top+1,l2)-af;
    		point c=q[pos1],d=q[pos2];
    		if(((b-a)*(c-a))*((b-a)*(d-a))<=0&&(((d-c)*(a-c))*((d-c)*(b-c))))
    			cout<<"BAD"<<'
    ';
    		else cout<<"GOOD"<<'
    ';
    	}
    }
    
  • 相关阅读:
    [四天学会ajax]JavaScript 和 Ajax 发出异步请求
    Visual studio 2010 中文版正式版无法安装Silverlight4 Tools的解决办法
    第一范式,第二范式,第三范式
    [四天学会ajax]利用 DOM 进行 Web 响应
    input 提示功能 CSS
    Asp.net中,从弹出窗体取选择值(转)
    WCF 学习笔记(二)
    网络流量监控程序
    VC.net 2005 中CString转成char *
    WCF 学习笔记(一)
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/11145659.html
Copyright © 2011-2022 走看看