HDU2948Geometry Darts(简单计算几何)
题目大意就是说两个人掷飞镖,飞镖在所给定的图形内就记一分,现在给定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 ;
}
HDU2948Geometry Darts(简单计算几何)的更多相关文章
- ●POJ 1556 The Doors(简单计算几何+最短路)
●赘述题目 10*10的房间内,有竖着的一些墙(不超过18个).问从点(0,5)到(10,5)的最短路. 按照输入样例,输入的连续5个数,x,y1,y2,y3,y4,表示(x,0--y1),(x,y2 ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- 2018.07.03 BZOJ 1007: [HNOI2008]水平可见直线(简单计算几何)
1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec Memory Limit: 162 MB Description 在xoy直角坐标平面上有n条直线L1,L2,-Ln, ...
- 2018.07.04 POJ 1654 Area(简单计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...
- 2018.07.04 POJ 3304 Segments(简单计算几何)
Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dimensional ...
- 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)
TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...
- 2018.07.03 POJ 2653 Pick-up sticks(简单计算几何)
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Description Stan has n sticks of various leng ...
- Gym 101917 E 简单计算几何,I 最大流
题目链接 https://codeforces.com/gym/101917 E 题意:给定一个多边形(n个点),然后逆时针旋转A度,然后对多边形进行规约,每个点的x规约到[0,w]范围内,y规约到[ ...
- 洛谷 - P1355 - 神秘大三角 - 简单计算几何
https://www.luogu.org/problemnew/show/P1355 判断一个点和三角形的位置关系,最简单的思路就是用向量. 首先排除掉和三角形顶点重合的情况. 把三角形设计成一个首 ...
随机推荐
- C#发送手机验证码
C#发送手机验证码,平台有很多,我就说说其中的1个平台 测试环境:.net2.0 测试效果:速度还可以,10秒内接收短信 1.去http://www.yuntongxun.com注册,会送8元测试金额 ...
- kthread_stop引起的OOP
1 使用kthread_create创建线程: struct task_struct *kthread_create(int (*threadfn)(void *data), void *da ...
- 一个基于WebGL的仿真3D水池有逼真的水波纹效果
最近在研究WebGL,看到国外很多高手做的很多超炫的3D效果,无比羡慕.忍不住把效果趴下来研究,下面介绍一个逼真的游泳池中浮动小球的效果.效果非常绚丽,功能强大.示例可切换观察水池的视角,不同视角考虑 ...
- 【Java】SHA加密
package sdfg; import java.math.BigInteger; import java.security.MessageDigest; import java.security. ...
- [转载] ubuntu下定制Vim/Gvim及使用技巧
vim是linux下的编辑器之神,是玩linux的必备工具,同样emacs是神的编辑器,两个编辑器是各有千秋,看个人的喜好,青菜萝卜各有所爱.我是比较喜欢vim,用vim编写bash,perl,pyt ...
- python开发学习-day01 (python安装与版本、字符串、字典、运算符、文件)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 【转】Android端与Android端利用WIFI进行FTP通信
原文网址:http://www.cnblogs.com/zhangkai5157/p/4303188.html 一.客户端通信工具类: import java.io.File; import java ...
- dynamic_cast
作为四个内部类型转换操作符之一的dynamic_cast和传统的C风格的强制类型转换有着巨大的差别.除了dynamic_cast以外的转换,其行为的都是在编译期就得以确定的,转换是否成功,并不依赖被转 ...
- Java 中带参无返回值方法的使用
有时方法的执行需要依赖于某些条件,换句话说,要想通过方法完成特定的功能,需要为其提供额外的信息才行.例如,现实生活中电饭锅可以实现“煮饭”的功能,但前提是我们必须提供食材,如果我们什么都不提供,那就真 ...
- [Papers]MHD, $\p_3\pi$, Lebesgue space [Cao-Wu, JDE, 2010]
$$\bex \p_3\pi\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=\frac{12}{7},\quad \frac{12}{7} ...