Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内
2014-08-15 19:34
225 查看
题目点击打开链接
凸多边形A, 多边形B, 判断B是否严格在A内。
注意AB有重点 。
将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。
或者说B上的某点在凸包的边上则也说明B不严格在A里面。
这个处理有个巧妙的方法,只需在求凸包的时候, <= 改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。
另外不能去重点。
凸多边形A, 多边形B, 判断B是否严格在A内。
注意AB有重点 。
将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。
或者说B上的某点在凸包的边上则也说明B不严格在A里面。
这个处理有个巧妙的方法,只需在求凸包的时候, <= 改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。
另外不能去重点。
int cmp(double x){ if(fabs(x) < 1e-8) return 0 ; return x > 0 ? 1 : -1 ; } struct point{ double x , y ; int k ; point(){} point(double _x , double _y):x(_x) , y(_y){} point operator - (const point &o){ return point(x - o.x , y - o.y) ; } friend double operator ^ (const point &a , const point &b){ return a.x * b.y - a.y * b.x ; } friend bool operator < (const point &a , const point &b){ if(cmp(a.x - b.x) != 0) return cmp(a.x - b.x) < 0 ; if(cmp(a.y - b.y) != 0) return cmp(a.y - b.y) < 0 ; return a.k < b.k ; } friend bool operator == (const point &a , const point &b){ return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0 ; } }; vector<point> convex_hull(vector<point> a){ vector<point> s(a.size() * 2 + 5) ; sort(a.begin() , a.end()) ; int m = 0 ; for(int i = 0 ; i < a.size() ; i++){ while(m > 1 && cmp((s[m-1] - s[m-2]) ^ (a[i] - s[m-2])) < 0) m-- ; s[m++] = a[i] ; } int k = m ; for(int i = a.size() - 2 ; i >= 0 ; i--){ while(m > k && cmp((s[m-1] - s[m-2]) ^ (a[i] - s[m-2])) < 0) m-- ; s[m++] = a[i] ; } s.resize(m) ; if(a.size() > 1) s.resize(m-1) ; return s ; } int main(){ int i , n , m , ans = 0 ; vector<point> lis(200000) ; cin>>n; for(i = 0 ; i < n ; i++){ scanf("%lf%lf" , &lis[i].x , &lis[i].y) ; lis[i].k = 0 ; } cin>>m ; for(i = 0 ; i < m ; i++){ scanf("%lf%lf" , &lis[n+i].x , &lis[n+i].y) ; lis[n+i].k = 1 ; } lis.resize(n + m) ; vector<point> hull = convex_hull(lis) ; for(i = 0 ; i < hull.size() ; i++){ if(hull[i].k){ ans = 1 ; break ; } } printf("%s\n" , ans ? "NO" : "YES") ; return 0 ; }
相关文章推荐
- Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包
- Codeforces Round #360 (Div. 1)A:二分图判断
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
- E. Vladik and cards Codeforces Round #384 (Div. 2) 好题 二分+(贪心+状态压缩DP)判断
- 【Codeforces Round 328 (Div 2)B】【找规律】The Monster and the Squirrel 正多边形连边分割块数
- 【Codeforces Round 263 (Div 2)A】【水题 认真读题】Appleman and Easy Task 每个点的相邻o是否都为偶数
- A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)
- Codeforces Round #360 (Div. 2) C DFS判断二分图
- 【Codeforces Round 354 (Div 2)E】【数学 多项式除法 讨论】The Last Fight Between Human and AI 多项式除以x-k是否值整除
- Codeforces Round #324 (Div. 2) (快速判断素数模板)
- 【Codeforces Round 329 (Div 2) B】【映射 排序 贪心】Anton and Lines 查看所有直线pair在[x1,x2]范围内是否有交点
- Codeforces Round #265 (Div. 2)D(判断立方体)
- 【Codeforces Round 335 (Div 2)E】【计算几何-凸包 线性规划 三分凸包上最优点】Freelancer's Dreams 二维属性 充最少的钱变得满足要求 [计算几何-凸包模
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
- 输出判断Codeforces Round #184 (Div. 2)
- 【codeforces 】Educational Codeforces Round 36 (Rated for Div. 2)(C.模拟 D.拓扑排序判断环)
- Codeforces Round #329 (Div. 2) B. Anton and Lines ([好题] 计算直线在区间是否有交点)
- 【Codeforces Round 272 (Div 2)A】【贪心 暴力 水题】Dreamoon and Stairs n个台阶每次走一步或两步是否有步数恰好为m倍数
- 【Codeforces Round 339 (Div 2)C】【计算几何 点到直线的距离模板】Peter and Snow Blower 多边形整体绕一圆心旋转的运行面积
- poj 1584 A Round Peg in a Ground Hole(判断凸多边形+圆是否在凸多边形内)