TOJ 3853 Farmer Flabby
2015-07-14 20:05
323 查看
Code pattern by kuangbin;
The portal:http://acm.tju.edu.cn/toj/showp3853.html
The portal:http://acm.tju.edu.cn/toj/showp3853.html
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <iostream> using namespace std; const double eps =1e-8; const double PI=acos(-1.0); struct Point { double x,y; Point(){} Point(double _x,double _y) { x=_x; y=_y; } Point operator -(const Point &b) const { return Point(x-b.x,y-b.y); } double operator ^(const Point &b) const { return x*b.y - y*b.x; } double operator *(const Point &b) const { return x*b.x + y*b.y; } }; struct Line { Point s,e; Line(){} Line(Point _s,Point _e) { s=_s; e=_e; } }; int sgn(double x) { if(fabs(x)<eps) return 0; if(x<0) return -1; else return 1; } bool Onseg(Point P,Line L) { return sgn((L.s-P)^(L.e-P)) ==0 && sgn((P.x-L.s.x) * (P.x - L.e.x)) <= 0 && sgn((P.y-L.s.y) * (P.y - L.e.y)) <=0; } int inConvexPoly(Point a,Point p[],int n) { for(int i=0; i<n; i++) { if(sgn((p[i]-a)^(p[(i+1)%n]-a)) <0) return -1; else if(Onseg(a,Line(p[i],p[(i+1)%n]))) return 0; } return 1; } void Deal_with() { int T,n,m; Point sheep[100005]; Point bar[55]; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i = 0 ; i < n ; i++) { scanf("%lf %lf",&sheep[i].x,&sheep[i].y); } scanf("%d",&m); for(int i = 0 ; i < m ; i++) { scanf("%lf %lf",&bar[i].x,&bar[i].y); } int cnt = 0; for(int i = 0 ; i < n ; i++) { if(inConvexPoly(sheep[i],bar,m) == -1)cnt ++; } printf("%d\n",cnt); } } int main(void) { //freopen("a.in","r",stdin); Deal_with(); return 0; }
相关文章推荐
- LeetCode 1: Two Sum
- Android清单文件详解(二) ---- 应用程序权限声明
- JS-003-innerText 与 innerHTML 区别
- java存取BLOB类型的数据
- Android中shape中的属性大全
- UITableView简单性能优化
- 3.osg中的CallBack回调、NodeVisitor与鼠标键盘的交互
- AAC LATM - 14496-3部分摘要
- 第十章:对象和类
- Qt画银白色Macbook
- 简单工厂
- 2.osg内置几何类型、osg::Geometry的类型与osg::MatrixTransform
- Swift2学习:Swift概览2-控制流
- leetcode2.1.8.3sum
- corosync配置与详解
- LeetCode题解——4SUm
- 调出软键盘 挤掉标题栏咋办
- 归档(plist)保存数据
- NSString,NSMutableString常见方法
- 10版word 插入分节符"连续"后变成 分节符"下一页"解决方法