E
来源:互联网 发布:地摊制作广告软件 编辑:程序博客网 时间:2024/05/10 03:48
判断一个点在是否在四边形的内部还是外部还是在四边形的边上,队友说是一个板子题目,就直接过了
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const double eps = 1e-8;int cmp(double x){ if(fabs(x)<eps)return 0; if(x>0)return 1; return -1;}struct point{ double x,y; point(double a = 0, double b = 0):x(a),y(b){} friend point operator-(const point &a,const point &b) { return point(a.x-b.x,a.y-b.y); }};double dot(const point &a,const point &b){ return a.x*b.x + a.y*b.y;}double det(const point &a,const point &b){ return a.x*b.y - a.y*b.x;}bool PointOnSegment(point p,point s,point t){ return cmp(det(p-s,t-s))==0 && cmp(dot(p-s,p-t))<=0;}struct polygon{ int n; point a[100]; polygon(){} int Point_In(point t) { int num = 0,i,d1,d2,k; a[n] = a[0]; for(int i = 0; i < n; i++) { if(PointOnSegment(t,a[i],a[i+1])) return 2; k = cmp(det(a[i+1]-a[i],t-a[i])); d1 = cmp(a[i].y - t.y); d2 = cmp(a[i+1].y - t.y); if(k>0 && d1<=0 && d2>0)num++; if(k<0 && d2<=0 && d1>0)num--; } return num != 0; }}poly;int main(){ int T; int s[100]; scanf("%d",&T); while(T--) { int cnt = 0; int n; point p; scanf("%d",&n); scanf("%lf%lf",&p.x,&p.y); while(n--) { scanf("%d",&poly.n); for(int i = 0; i < poly.n; i++) { scanf("%lf%lf",&poly.a[i].x,&poly.a[i].y); } int ans = poly.Point_In(p); s[cnt++] = ans; } for(int i = 0; i < cnt; i++) { if(i==0) { if(s[i]==2) cout<<"0"; else if(s[i]==1) cout<<"1"; else cout<<"2"; } else { if(s[i]==2) cout<<" 0"; else if(s[i]==1) cout<<" 1"; else cout<<" 2"; } } cout<<endl; } return 0;}
阅读全文
1 0
- e
- E
- E
- e
- e
- e
- e
- e
- E
- e
- E
- e
- e
- E
- e
- e
- e
- E
- 回调函数
- Android插件化原理解析——概要
- Excption与Error包结构。OOM你遇到过哪些情况,SOF你遇到过哪些情况
- ElasticSearch入门 第九篇:实现正则表达式查询的思路
- 彻底搞定Android开发中软键盘的常见问题
- E
- c++11 lambda函数
- struts2 Convention插件零配置,使用注解开发
- Linux系统 各种目录 的作用(转载 谨作笔记)
- JZOJ 5437. 【NOIP2017提高A组集训10.31】Sequence
- POJ-3468 A Simple Problem with Integers
- test
- Kafka设计解析(三)- Kafka High Availability (下)
- too many connections 分析