题意:

有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的更多相关文章

  1. LA 3890 (半平面交) Most Distant Point from the Sea

    题意: 给出一个凸n边形,求多边形内部一点使得该点到边的最小距离最大. 分析: 最小值最大可以用二分. 多边形每条边的左边是一个半平面,将这n个半平面向左移动距离x,则将这个凸多边形缩小了.如果这n个 ...

  2. LA 2218 Triathlon(半平面交)

    Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...

  3. POJ 1755 Triathlon [半平面交 线性规划]

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6912   Accepted: 1790 Descrip ...

  4. POJ 1755 Triathlon (半平面交)

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4733   Accepted: 1166 Descrip ...

  5. POJ 1755 Triathlon(线性规划の半平面交)

    Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...

  6. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  7. LA 4992 Jungle Outpost(半平面交)

    Jungle Outpost [题目链接]Jungle Outpost [题目类型]半平面交 &题解: 蓝书282 我自己写的代码居然AC了!!! 刘汝佳的说要right要-3什么的,还要特判 ...

  8. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

  9. LA2218 Triathlon /// 半平面交 oj22648

    题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...

随机推荐

  1. 微信诡异的 40029 不合法的oauth_code

    最近几天在做微信公共平台开发,之前一切正常运行着,发布一套程序出去之后,发现时不时的报错! 小总结下问题出现原因:微信oauth2.0 接口说明 第一步:用户同意授权,获取code 在确保微信公众账号 ...

  2. [转载]非常完善的Log4net详细说明

    前言 此篇文章是我见过写得最好的一片关于Log4Net的文章,内容由简入难,而且面面俱到,堪称入门和精通的佳作,特从懒惰的肥兔的转载过来. 1.概述 log4net是.Net下一个非常优秀的开源日志记 ...

  3. Django 学习笔记之二 基本命令

    1.新建一个 django project 在Django安装路径下找到django-admin.py文件,我的路径是在C:\Python27\Lib\site-packages\Django-1.1 ...

  4. oracle 删除用户,表空间;循环删除表

    select * from dba_tablespaces 说明:查看所有表空间 ----------------------------------------------------------- ...

  5. python 基于小顶堆实现随机抽样

    起因:之前用蓄水池抽样,算法精简,但直观性很差. 所以这次采用了简单的,为没一个行,赋值一个随机值,然后取 最大的K个作为,随机样本. 基本思路:为每一个行(record,记录,实体) 赋一个rand ...

  6. 【WCF--初入江湖】10 序列化和传输大型数据流

    10 序列化和传输大型数据流 1.前言 理解WCF的序列化形式 掌握DataContractSerializer序列化对象 比较性能 比较xmlSerializer序列化对象   大数据量传输设置 修 ...

  7. SVN库实时同步设置

    为了安全起见,SVN服务器除了做定时全量备份和增量备份以外,如条件允许,可做实时备份. 这需要2台机器,一台是master server,另一台做mirror server.master做主服务,mi ...

  8. C# 面向对象之概念理解(3)

    多态 多态是指两个或多个属于不同类的对象,对同一个消息(方法调用)做出不同响应的能力. 多态(<韦氏大词典>)中定义:可以呈现不同形式的能力或状态. C#如何实现多态的知识——即继承上覆载 ...

  9. 通过快捷键及cmd命令注销系统

    公司的外网内网是隔离的 外网的远程电脑屏幕一半卡那了,页面注销键正好在卡死的那一半屏幕上,用以下简单方法注销远程重新连接,问题解决了. 1.通过快捷键win+r打开“运行...” 2.输入CMD 回车 ...

  10. 0环境设置 - SQLPLUS设置

    define _editor=vi - SQL*PLUS默认编辑器set serveroutput on size 1000000 - 默认打开DBMS_OUTPUT, 不用每次使用都执行这个命令来启 ...