Polygons
来源:互联网 发布:原画网络班 编辑:程序博客网 时间:2024/04/30 16:42
/*
题意:判断一个顺时针凸包A是否包含(不包括边界)简单多边形B
分析:判断B的每个点是否在A内; 因为n是1e5,m是1e4,如果判断算法在log(m)数量级左右, O(n * Olog(m) )可以过
*/
#include <iostream>#include <cstring>#include <string>#include <cmath>#include <algorithm>#include <cstdio>#include <cstdlib>#include <vector>#include <queue>#include <deque>#define MAX 200005#define INF 1e8#define FOR(i, n) for(int i = 0; i < n; i++)#define FORB(i, n) for(int i = n - 1; i >= 0; i--)#define MP(i, j) make_pair(i, j)#define MEM(array, val) memset(array, val, sizeof(array))#define pu first#define pv second#define eps 1e-50#define INF 1e50using namespace std;inline int cmpd(double x){ return x > eps ? 1 : ( x < - eps ? - 1 : 0); }inline double sqr(double x){ return x * x;}inline bool zero(double x){return cmpd(x) == 0;}int sgn(double x){ return x > eps ? 1 : (x < -eps? -1 : 0); }struct Point{ double x, y; Point(){} Point(const double &xx, const double &yy):x(xx), y(yy){} 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 &w)const { return Point(x / w, y / w); } friend double dot(const Point &a, const Point &b){ return a.x *b.x + a.y * b.y; } friend double det(const Point &a, const Point &b){ return a.x * b.y - a.y * b.x; } void in(){ scanf("%lf %lf",&x, &y); } void out(){ printf("%.2f %.2f\n", x, y); }};struct Poly{ vector<Point>p; Poly(){} bool isContain(const Point &t){ int n = p.size(); Point g = (p[0] + p[n/3] + p[n * 2 / 3]) / 3.0; int r = n, l = 0; while(l + 1 < r){ int mid = (l + r)>> 1; int k = sgn(det(p[l] - g, p[mid] - g) ); int resl = sgn( det(p[l] - g, t - g) ); int resm = sgn(det(p[mid] - g, t - g) ); if(k < 0){ if(resl <= 0 && resm > 0){ r = mid; }else{ l = mid; } }else { if(resl > 0 && resm <= 0){ l = mid; }else { r = mid; } } } r %= n; int z = sgn( det(p[r] - t, p[l] - t) );// cout<<z<<endl; if(z == 1){ return true; } return false; }}A;int n, m;int main(){ cin>>n; Point tt; FOR(i, n){ tt.in(); A.p.push_back(tt);//顺时针严格凸包 } bool isInSide = true; cin>>m; FOR(j, m){ tt.in(); if(isInSide == true && !A.isContain(tt)){ isInSide= false; } } if(isInSide){ puts("YES"); }else { puts("NO"); } return 0;}/*6 -2 1 0 3 3 3 4 1 3 -2 2 -2 4 0 1 2 2 3 1 1 05 1 2 4 2 3 -3 -2 -2 -2 1 4 0 1 1 2 4 1 2 -15 -1 2 2 3 4 1 3 -2 0 -3 5 1 0 1 1 3 1 5 -1 2 -1*/
- Polygons
- Shrinking Polygons hust 14048
- UVA 10005 Packing polygons
- UVA 137 Polygons
- Codeforces 166B - Polygons
- uva10005(Packing polygons)
- [UVA10005]Packing polygons
- UVa 10005 - Packing polygons
- codeforces 166 B. Polygons
- POJ1389-Area of Simple Polygons
- POJ1389[Area of Simple Polygons]
- HDU 1632 Polygons (凸包)
- poj1389 Area of Simple Polygons
- Area of Triangles and Polygons (2D)
- poj 1389 Area of Simple Polygons
- poj 1389 Area of Simple Polygons
- PKU 1389 Area of Simple Polygons
- POJ-1389-Area of Simple Polygons
- hdu2236(二分法)
- shell执行中出现那的问题
- hdu1241&&SDJZUOJ 2140 Oil Deposit
- c++中vector的用法详解
- bfs+dfs(poj3083)
- Polygons
- EFProf Entity Framework Profile 工具
- 大话设计模式之代理模式
- 杭电1022-Train Problem I
- 黑马程序员-IO流
- error LNK2019: 无法解析的外部符号 __imp____glutCreateWindowWithExit@8,该符号在函数 _glutCreateWindow_ATEXIT_HA
- BI学习走过的路---MSSQL 2008 安装过程
- 正确设置Visual Studio当前Platform SDK(Windows SDK)版本的方法
- 用CFile类时,遇到“试图越过其尾端对一个未命名的文件进行读写”