其他分享
首页 > 其他分享> > 凸多边形 HRBUST - 1429 计算几何_凸包_未调完

凸多边形 HRBUST - 1429 计算几何_凸包_未调完

作者:互联网

Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath> 
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 200000 
const double eps = 0.000000000001; 
using namespace std; 
int n,m; 
struct Point {
    double x,y;
    Point (double x = 0,double y = 0) : x(x),y(y){} 
}point[maxn],ask[maxn]; 
int exis(double t) { return (fabs(t) <= eps) ? 0 : (t < 0 ? -1 : 1); }
double det(double x1,double y1,double x2,double y2) { return x1*y2-x2*y1; }  
double cross(Point a,Point b,Point c) { return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y); }  
bool solve(){ 
    memset(point,0,sizeof(point)); 
    memset(ask,0,sizeof(ask)); 
    for(int i = 1;i <= n; ++i) scanf("%lf%lf",&point[i].x,&point[i].y); 
    scanf("%d",&m); 
    for(int i = 1;i <= m; ++i) scanf("%lf%lf",&ask[i].x,&ask[i].y);  
    for(int i = 1;i <= m; ++i) {
        int l = 2,r = n,ans = 0; 
        if(exis(cross(point[1],ask[i],point[2])) != 1 || exis(cross(point[1],ask[i],point[n])) != -1) 
            return false;               
        while(l <= r) {
            int mid = (l + r) >> 1; 
            if(exis(cross(point[1],point[mid],ask[i])) == -1) 
                r = mid - 1;
            else 
                ans = mid,l = mid + 1; 
        }
        if(!(exis(cross(point[ans-1],point[ans],ask[i])) == -1)) return false; 
    }
    return true; 
} 

int main(){
    //setIO("input"); 
    while(scanf("%d",&n)!=EOF)
    {
        if(solve()) 
            printf("YES\n"); 
        else 
            printf("NO\n");
    }
    return 0; 
} 

  

标签:HRBUST,return,point,1429,double,凸多边形,mid,int,include
来源: https://www.cnblogs.com/guangheli/p/10540014.html