LA 2218 (半平面交) Triathlon
题意:
有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过。
对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列)。
分析:
粗一看,这不像一道计算几何的题目。
假设赛道总长度是1,第一段长x,第二段长y,第三段则是1-x-y
那么可以计算出每个选手完成比赛的时间Ti
对于选手i,若要成为冠军则有Ti < Tj (i ≠ j)
于是就有n-1个不等式,每个不等式都代表一个半平面。
在加上x>0, y>0, 1-x-y>0 这三个半平面一共有n+2个半平面。如果这些半平面交非空,则选手i可以成为冠军。
最终,还是转化成了半平面交的问题。
细节:
- 对于半平面 ax+by+c > 0 所对应的向量(b, -a)是和系数的正负没有关系的,可以自己试验下。开始我纠结了好长时间
if(fabs(a) > fabs(b)) P = Point(-c/a, )
else P = Point(, -c/b);对于这段代码不是太清楚它的含义,因为不管怎样P都是在ax+by+c = 0 这条直线上的。我猜可能是减小浮点运算的误差吧?
//#define LOCAL
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; const double eps = 1e-;
const int maxn = + ;
int v[maxn], u[maxn], w[maxn]; struct Point
{
double x, y;
Point(double x=, double y=):x(x), y(y) {}
};
typedef Point Vector;
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); }
Vector operator * (Vector a, double p) { return Vector(a.x*p, a.y*p); }
Vector operator / (Vector a, double p) { return Vector(a.x/p, a.y/p); }
bool operator < (const Point& a, const Point& b)
{ return a.x < b.x || (a.x == b.x && a.y < b.y); }
bool operator == (const Point& a, const Point& b)
{ return a.x == b.x && a.y == b.y; }
double Dot(const Vector& a, const Vector& b) { return a.x*b.x + a.y*b.y; }
double Cross(const Vector& a, const Vector& b) { return a.x*b.y - a.y*b.x; }
double Length(const Vector& a) { return sqrt(Dot(a, a)); }
Vector Normal(const Vector& a)
{
double l = Length(a);
return Vector(-a.y/l, a.x);
} double PolygonArea(const vector<Point>& p)
{
int n = p.size();
double ans = 0.0;
for(int i = ; i < n-; ++i)
ans += Cross(p[i]-p[], p[i+]-p[]);
return ans/;
} struct Line
{
Point P;
Vector v;
double ang;
Line() {}
Line(Point p, Vector v):P(p), v(v) { ang = atan2(v.y, v.x); }
bool operator < (const Line& L) const
{
return ang < L.ang;
}
}; bool OnLeft(const Line& L, Point p)
{
return Cross(L.v, p-L.P) > ;
} Point GetLineIntersevtion(const Line& a, const Line& b)
{
Vector u = a.P - b.P;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.P + a.v*t;
} vector<Point> HalfplaneIntersection(vector<Line> L)
{
int n = L.size();
sort(L.begin(), L.end()); int first, last;
vector<Point> p(n);
vector<Line> q(n);
vector<Point> ans; q[first=last=] = L[];
for(int i = ; i < n; ++i)
{
while(first < last && !OnLeft(L[i], p[last-])) last--;
while(first < last && !OnLeft(L[i], p[first])) first++;
q[++last] = L[i];
if(fabs(Cross(q[last].v, q[last-].v)) < eps)
{
last--;
if(OnLeft(q[last], L[i].P)) q[last] = L[i];
}
if(first < last) p[last-] = GetLineIntersevtion(q[last-], q[last]);
}
while(first < last && !OnLeft(q[first], p[last-])) last--;
if(last - first <= ) return ans;
p[last] = GetLineIntersevtion(q[first], q[last]); for(int i = first; i <= last; ++i) ans.push_back(p[i]);
return ans;
} int main(void)
{
#ifdef LOCAL
freopen("2218in.txt", "r", stdin);
#endif int n;
while(scanf("%d", &n) == && n)
{
for(int i = ; i < n; ++i) scanf("%d%d%d", &v[i], &u[i], &w[i]);
for(int i = ; i < n; ++i)
{
int ok = ;
double k = ;
vector<Line> L;
for(int j = ; j < n; ++j) if(j != i)
{
if(v[i]<=v[j] && u[i]<=u[j] && w[i]<=w[j]) { ok = ; break; }
if(v[i]>v[j] && u[i]>u[j] && w[i]>w[j]) continue; double a = (k/v[j]-k/v[i]+k/w[i]-k/w[j]);
double b = (k/u[j]-k/u[i]+k/w[i]-k/w[j]);
double c = k/w[j]-k/w[i];
//L.push_back(Line(Point(0, -c/b), Vector(b, -a)));
Point P;
Vector V(b, -a);
if(fabs(a) > fabs(b)) P = Point(-c/a, );
else P = Point(, -c/b);
L.push_back(Line(P, V));
}
if(ok)
{
L.push_back(Line(Point(, ), Vector(, -)));
L.push_back(Line(Point(, ), Vector(, )));
L.push_back(Line(Point(, ), Vector(-, )));
vector<Point> Poly = HalfplaneIntersection(L);
if(Poly.empty()) ok = ;
}
if(ok) puts("Yes"); else puts("No");
}
} return ;
}
代码君
LA 2218 (半平面交) Triathlon的更多相关文章
- LA 3890 (半平面交) Most Distant Point from the Sea
题意: 给出一个凸n边形,求多边形内部一点使得该点到边的最小距离最大. 分析: 最小值最大可以用二分. 多边形每条边的左边是一个半平面,将这n个半平面向左移动距离x,则将这个凸多边形缩小了.如果这n个 ...
- LA 2218 Triathlon(半平面交)
Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...
- POJ 1755 Triathlon [半平面交 线性规划]
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6912 Accepted: 1790 Descrip ...
- POJ 1755 Triathlon (半平面交)
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4733 Accepted: 1166 Descrip ...
- POJ 1755 Triathlon(线性规划の半平面交)
Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- LA 4992 Jungle Outpost(半平面交)
Jungle Outpost [题目链接]Jungle Outpost [题目类型]半平面交 &题解: 蓝书282 我自己写的代码居然AC了!!! 刘汝佳的说要right要-3什么的,还要特判 ...
- LA 3890 Most Distant Point from the Sea(半平面交)
Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...
- LA2218 Triathlon /// 半平面交 oj22648
题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...
随机推荐
- Discuz!NT 后台任意文件上传的源代码修补方法
相关的漏洞介绍: http://www.wooyun.org/bugs/wooyun-2013-035199 Discuz!NT 管理后台可以自定义文件类型,从而造成任意文件上传,测试过程中 aspx ...
- Enabled AWE
sp_configure RECONFIGURE GO sp_configure RECONFIGURE GO sp_configure RECONFIGURE GO sp_configure REC ...
- [转]GLES 3.0 新特性
转自: http://www.ifanr.com/131333 OpenGL ES 3.0 带来很多新特性,根据 AnandTech 的解释: 支持更多缓冲区对象.在 OpenGL ES 2.0 时中 ...
- 一个简单的PHP登录演示(SESSION版 与 COOKIE版)
//==============COOKIE版本的简单登录================ if ($_GET[out]){ setcookie('id',''); setcookie('pw','' ...
- trie树--详解
文章作者:yx_th000 文章来源:Cherish_yimi (http://www.cnblogs.com/cherish_yimi/) 转载请注明,谢谢合作.关键词:trie trie树 数据结 ...
- hdu 2102 A计划(BFS,基础)
题目 //要仔细写的BFS,着重对#穿越的处理哦: //花了几个小时终于把这道简单的BFS给弄好了,我果然还需要增加熟练度,需要再仔细一些: //代码有点乱,但我不想改了,,,,, #include& ...
- GOOGLE搜索秘籍完全公开
一,GOOGLE简介 Google(www.google.com)是一个搜索引擎,由两个斯坦福大学博士生Larry Page与Sergey Brin于1998年9月发明,Google Inc. 于19 ...
- POJ1068Parencodings
http://poj.org/problem?id=1068 这个题的话就是先把给出来的一串数字转化成括号,再把括号转化成要求的,最后输出就行了 #include<cstdio> #inc ...
- BFS 模板
转自:欣哥 下面是bfs一般的形式,谈不上模板但一般都这么来做有点乱有什么多交流 bfs一般用于求最短时间 #include<stdio.h>#include<queue>us ...
- 李洪强iOS开发支付集成之支付宝支付
iOS开发支付集成之支付宝支付 下载支付宝SDK 首先是开发包下载,还是比较难发现的,网上以前文章中的链接都打不开,我找了好久才找到的.最新的地址在这里(注意的是下载出来的SDK包里面并没有传说中的开 ...