题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2948
纯数学题,写起来有点烦,主要是点在三角形内就是点到三角形任意两点组成的三个三角形面积和等于原三角形面积+海伦公式。
代码:
#include <bits/stdc++.h>
using namespace std;
struct shape {
char name;
double x, y, r;
double x1, x2, x3, y1, y2, y3;
} SP[1005];
int n, t;
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2));
}
int circle(int i, double x, double y) {
if(dist(SP[i].x, SP[i].y, x, y) < SP[i].r) {
return 1;
}
return 0;
}
int rect(int i, double x, double y) {
if(x > SP[i].x1 && x < SP[i].x2 && y > SP[i].y1 && y < SP[i].y2)
return 1;
return 0;
}
double getS(double d1, double d2, double d3) {
double p = (d1 + d2 + d3) / 2;
return sqrt(p * (p-d1) * (p-d2) * (p-d3));
}
int tri(int i, double x, double y) {
// printf("%lf %lf %lf", dist(SP[i].x1, SP[i].y1, SP[i].x2, SP[i].y2), dist(SP[i].x1, SP[i].y1, SP[i].x2, SP[i].y2), dist(SP[i].x1, SP[i].y1, SP[i].x2, SP[i].y2));
double s1 = getS(dist(SP[i].x1, SP[i].y1, SP[i].x2, SP[i].y2),
dist(SP[i].x1, SP[i].y1, x, y),
dist(x, y, SP[i].x2, SP[i].y2));
double s2 = getS(dist(SP[i].x1, SP[i].y1, SP[i].x3, SP[i].y3),
dist(SP[i].x1, SP[i].y1, x, y),
dist(x, y, SP[i].x3, SP[i].y3));
double s3 = getS(dist(SP[i].x3, SP[i].y3, SP[i].x2, SP[i].y2),
dist(SP[i].x3, SP[i].y3, x, y),
dist(x, y, SP[i].x2, SP[i].y2));
double s = getS(dist(SP[i].x1, SP[i].y1, SP[i].x2, SP[i].y2),
dist(SP[i].x3, SP[i].y3, SP[i].x2, SP[i].y2),
dist(SP[i].x1, SP[i].y1, SP[i].x3, SP[i].y3));
// 此处有坑,1e-7都是WA
if(fabs(s1 + s2 + s3 - s) < 1e-6) {
return 1;
}
return 0;
}
int solve(double x, double y) {
int ans = 0;
for (int i = 0; i < n; i ++) {
if(SP[i].name == 'C') {
ans += circle(i, x, y);
}
if(SP[i].name == 'R') {
ans += rect(i, x, y);
}
if(SP[i].name == 'T') {
ans += tri(i, x, y);
}
}
return ans;
}
int main() {
double x, y;
char flg;
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i ++) {
scanf("%c",&flg);
if(flg == 'C') {
scanf("%lf%lf%lf", &SP[i].x, &SP[i].y, &SP[i].r);
}
if(flg == 'R') {
scanf("%lf%lf%lf%lf", &SP[i].x1, &SP[i].y1, &SP[i].x2, &SP[i].y2);
}
if(flg == 'T') {
scanf("%lf%lf%lf%lf%lf%lf", &SP[i].x1, &SP[i].y1, &SP[i].x2, &SP[i].y2,&SP[i].x3, &SP[i].y3);
}
SP[i].name = flg;
getchar();
}
scanf("%d", &t);
while (t --) {
int s1 = 0, s2 = 0;
for (int i = 0; i < 6; i ++) {
scanf("%lf%lf", &x, &y);
if(i < 3) {
s1 += solve(x, y);
} else {
s2 += solve(x, y);
}
}
if(s1 > s2) {
printf("Bob\n");
} else if(s1 < s2) {
printf("Hannah\n");
} else {
printf("Tied\n");
}
}
return 0;
}