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

论坛 期权论坛 脚本     
匿名技术用户   2021-1-7 05:55   585   0

凸多边形 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; 
} 

  

posted @ 2019-03-15 22:41 EM-LGH 阅读( ...) 评论( ...) 编辑 收藏
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP