您的位置:首页 > 其它

TOJ 3853 Farmer Flabby

2015-07-14 20:05 323 查看
Code pattern by kuangbin;

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: