题目大意就是说两个人掷飞镖,飞镖在所给定的图形内就记一分,现在给定N个图形(圆、三角形和矩形),问每一次比赛(没人分别掷三次)谁赢。

 #include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-12
#define MAXN 55
#define INF 1e30
#define mem0(a) memset(a,0, sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
double MAX(double a, double b) {return a > b ? a : b;}
double MIn(double a, double b) {return a < b ? a : b;}
typedef long long LL;
/****************************************计算几何头文件**************************************************/
struct Point{
double x,y;
Point(double x=, double y=):x(x),y(y){}
}; struct Polygon
{
Point p[MAXN];
int Size;
}; struct Circle
{
Point o;
double r;
Circle(){}
Circle(Point _o, double _r):o(_o),r(_r){}
}; Point operator + (Point A, Point B) {return Point(A.x+B.x, A.y+B.y);} Point operator - (Point A, Point B) {return Point(A.x-B.x, A.y-B.y);} Point operator * (Point A, double p) {return Point(A.x*p, A.y*p);} Point operator / (Point A, double p) {return Point(A.x/p, A.y/p);} int dcmp(double x) {
if(fabs(x) < eps) return ;
else return x < ? - : ;
} bool operator == (const Point &A, const Point &B) {
return dcmp(A.x-B.x) == && dcmp(A.y-B.y) == ;
} double Dot(Point A, Point B) { return A.x*B.x + B.y*B.y;} //点积 double Length(Point A) { return sqrt(Dot(A,A));} //向量长度 double Angle(Point A, Point B) {return acos(Dot(A,B) / Length(A) / Length(B));}//向量夹角 double cross(Point A, Point B) {return A.x*B.y - A.y*B.x;} bool crossed(Point a, Point b, Point c, Point d)//线段ab和cd是否相交
{
if(cross(a-c, d-c)*cross(b-c, d-c)<= && cross(c-a, b-a)*cross(d-a, b-a)<=)
{
return true;
}
return false;
} bool isPointOnSegent(Point p, Point s, Point e)//判断点是否在线段se上
{
double d = (p.x-s.x) * (e.x-p.x);
double a = (p.y-s.y) / (p.x-s.x);
double b = (e.y-p.y) / (e.x-p.x);
if(dcmp(d)== && dcmp(a-b)==)return true;
return false;
} int isPointInPolygon(Point p, Polygon poly)//判断点是否在多边形以内
{
int w = ;
int n = poly.Size;
for(int i=;i<n;i++)
{
if(isPointOnSegent(p, poly.p[i], poly.p[(i+)%n])) return ;//点在边上
int k = dcmp(cross(poly.p[(i+)%n]-poly.p[i], p-poly.p[i]));
int d1 = dcmp(poly.p[i].y - p.y);
int d2 = dcmp(poly.p[(i+)%n].y - p.y);
if(k > && d1 <= && d2 > ) w++;
if(k < && d2 <= && d1 > ) w--;
}
if(w != ) return ;
return ;
} /****************************************************************************************************/
struct R
{
Point a, b;
R(){}
R(Point _a, Point _b)
{
a = _a;
b = _b;
}
}r[];
struct T
{
Point a, b, c;
T(){}
T(Point _a, Point _b, Point _c) {
a = _a; b = _b; c = _c;
}
}t[];
Circle c[];
int S, N;
int cntC = , cntT = , cntR = ; int calc(double x, double y)//计算点(x, y)在图中的多少个图形内部
{
Point p = Point(x, y);
int ans = ;
for(int i=;i<cntC;i++)
{
if(Length(p-c[i].o) <= c[i].r) ans ++;
}
for(int i=;i<cntT;i++)
{
if( cross(t[i].c-t[i].a, p-t[i].a)*cross(t[i].b-t[i].a, p-t[i].a)<=
&& cross(t[i].a-t[i].b, p-t[i].b)*cross(t[i].c-t[i].b, p-t[i].b)<= ) ans ++;
}
for(int i=;i<cntR;i++)
{
if(x>=r[i].a.x&&x<=r[i].b.x && y>=r[i].a.y&&y<=r[i].b.y) ans ++;
}
return ans;
} int main()
{
char ch;double x, y, rr;
while(~scanf("%d%*c", &S))
{
cntT = cntC = cntR = ;
for(int i=;i<S;i++)
{
scanf("%c", &ch);
if(ch == 'C')
{
scanf("%lf %lf %lf%*c", &x, &y, &rr);
c[cntC++] = Circle(Point(x, y), rr);
continue;
}
else if(ch == 'T')
{
Point aa[];
for(int j=;j<;j++)
{
scanf("%lf%*c%lf%*c", &x, &y);
aa[j] = Point(x, y);
}
t[cntT++] = T(aa[],aa[],aa[]);
}
else
{
Point aa[];
for(int j=;j<;j++)
{
scanf("%lf%*c%lf%*c", &x, &y);
aa[j] = Point(x, y);
}
r[cntR++] = R(aa[], aa[]);
}
}
scanf("%d", &N);
for(int i=;i<N;i++)
{
int cntA = , cntB = ;
for(int j=;j<;j++)
{
scanf("%lf %lf", &x, &y);
cntA += calc(x, y);
}
for(int j=;j<;j++)
{
scanf("%lf %lf", &x, &y);
cntB += calc(x, y);
}
// printf("%d %d\n", cntA, cntB);
printf("%s\n", cntA > cntB ? "Bob" : (cntA == cntB ? "Tied" : "Hannah"));
}
}
return ;
}
04-18 01:56