【O(nlgn)判定点在凸包内】Codeforces Round #113 (Div. 2) B
来源:互联网 发布:华为手机4g网络变成2g 编辑:程序博客网 时间:2024/06/04 18:04
思路参考了这个bloghttp://hi.baidu.com/aekdycoin/blog/item/7abf85026f0d7e85d43f7cfe.html
复杂度是O(nlgn)
#define N 100005struct node{ double x,y;}a[100005];double cross(node a,node b,node c){//>0,ab在ac顺时针;<0,ab在ac逆时针 return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);}int n,m;bool chk(node b){ int i,j; if(cross(a[0],b,a[1]) <= 0)return false; if(cross(a[0],b,a[n-1]) >= 0)return false; int l = 0,r = n-1,mid; int tag = 0; while(l<=r){ mid = (l+r)>>1; if(cross(a[0],b,a[mid]) >= 0){ tag = mid; l = mid+1; } else r = mid-1; } l = tag,r = tag+1; if(cross(a[l],b,a[r]) <= 0)return false; return true;}int main(){ cin>>n; int i,j; for(i=0;i<n;i++){ cin>>a[i].x>>a[i].y; } int ans = 0; cin>>m; node b; for(i=0;i<m;i++){ cin>>b.x>>b.y; if(chk(b))ans++; } if(ans==m)cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0;}
- 【O(nlgn)判定点在凸包内】Codeforces Round #113 (Div. 2) B
- Codeforces Round #221 (Div. 2) B. I.O.U.
- Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内
- Codeforces Round #142 (Div. 2) B. T-primes (数学、O(n)筛素数)
- 【计算几何】Codeforces Round #113 (Div. 2)-B. Polygons
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- Codeforces Round #171 (Div. 2) B
- Codeforces Round #169 (Div. 2) B题
- Codeforces Round #188 (Div. 2) B题
- Codeforces Round #192 (Div. 2) B
- Codeforces Round #203 (Div. 2) B. Resort
- Codeforces Round #206 (Div. 2) - b
- Codeforces Round #202 (Div. 2)B-贪心
- iOS: load external image and css to UIWebView
- Linux 命令集锦
- Mac:如何应对证书过期
- C和指针学习
- C语言经典著作导读
- 【O(nlgn)判定点在凸包内】Codeforces Round #113 (Div. 2) B
- Linux网络编程必看书籍推荐
- poj 1737
- Linux Epoll介绍和程序实例
- Android权限
- Linux下各类TCP网络服务器的实现源代码
- 多路IO复用模型 select epoll 等
- 按位与、或、异或等运算方法
- C语言九阴真经