题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利。

思路:把题意转化为一个不等式,设比赛长度是1,如果i要战胜j,x、y分别是第一阶段和第二阶段的比赛长度: (x / ui + y / vi + (1-x-y) / wi) < (x / uj + y / vj + (1-x-y) / wj) 可以转化为Ax + By + C > 0的形式,也就可以用半平面交来解决,对于每个i都有其他n-1个j的半平面和x>0, y>0, (1-x-y)>0这三个半平面,如果这些半平面(n+2)都有交集,说明i有可能打败其他选手,否则不可能。

此题值得注意的是精度问题,选P点时(L上的一点),如果默认P=Point(-c/a,0),能过,但是只是P = Point(0, -c/b),就不行了。计算几何一点要注意精度问题!!!

 #include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<memory.h>
#include<cstdlib>
#include<vector>
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long int
#define up(i,x,y) for(i=x;i<=y;i++)
#define w(a) while(a)
const double inf=0x3f3f3f3f;
const int N = ;
const double eps = *1e-;
const double PI = acos(-1.0);
using namespace std; struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B)
{
return Vector(A.x+B.x, A.y+B.y);
}
Vector operator - (const Point& A, const Point& B)
{
return Vector(A.x-B.x, A.y-B.y);
}
Vector operator * (const Vector& A, double p)
{
return Vector(A.x*p, A.y*p);
}
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/L);
} double PolygonArea(vector<Point> p)
{
int n = p.size();
double area = ;
for(int i = ; i < n-; i++)
area += Cross(p[i]-p[], p[i+]-p[]);
return area/;
} // 有向直线。它的左边就是对应的半平面
struct Line
{
Point P; // 直线上任意一点
Vector v; // 方向向量
double ang; // 极角,即从x正半轴旋转到向量v所需要的角(弧度)
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;
}
}; // 点p在有向直线L的左边(线上不算)
bool OnLeft(const Line& L, const Point& p)
{
return Cross(L.v, p-L.P) > ;
} // 二直线交点,假定交点惟一存在
Point GetLineIntersection(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;
} const double INF = 1e8; // 半平面交主过程
vector<Point> HalfplaneIntersection(vector<Line> L)
{
int n = L.size();
sort(L.begin(), L.end()); // 按极角排序 int first, last; // 双端队列的第一个元素和最后一个元素的下标
vector<Point> p(n); // p[i]为q[i]和q[i+1]的交点
vector<Line> q(n); // 双端队列
vector<Point> ans; // 结果 q[first=last=] = L[]; // 双端队列初始化为只有一个半平面L[0]
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-] = GetLineIntersection(q[last-], q[last]);
}
while(first < last && !OnLeft(q[first], p[last-])) last--; // 删除无用平面
if(last - first <= ) return ans; // 空集
p[last] = GetLineIntersection(q[last], q[first]); // 计算首尾两个半平面的交点 // 从deque复制到输出中
for(int i = first; i <= last; i++) ans.push_back(p[i]);
return ans;
} const int maxn = + ;
int V[maxn], U[maxn], W[maxn];
int main()
{
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(i != j)
{
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;
// x/V[i]+y/U[i]+(1-x-y)/W[i] < x/V[j]+y/U[j]+(1-x-y)/W[j]
// ax+by+c>0
double a = (k/V[j]-k/W[j]) - (k/V[i]-k/W[i]);
double b = (k/U[j]-k/W[j]) - (k/U[i]-k/W[i]);
double c = k/W[j] - k/W[i];
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)
{
// x>0, y>0, x+y<1 ==> -x-y+1>0
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) printf("Yes\n");
else printf("No\n");
}
}
return ;
}

uva 2218 Triathlon的更多相关文章

  1. LA 2218 Triathlon(半平面交)

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

  2. uva 1298 - Triathlon

    半平面交的题: 这个题目的亮点就是建模: #include<cstdio> #include<algorithm> #include<cmath> #define ...

  3. UVALive 2218 Triathlon

    https://vjudge.net/problem/UVALive-2218 题意: 铁人三项比赛,每项比赛长度未定,已知每个选手每项比赛的平均速度. 设计每项比赛的长度,让其中某个特定选手获胜. ...

  4. LA 2218 (半平面交) Triathlon

    题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. html5 Doctor——教你规范使用html5标签

    学习地址(英文资料):http://html5doctor.com/ http://www.w3.org/html/wg/drafts/html/master/text-level-semantics ...

  2. [转载].Net中如何操作IIS(源代码)

    ///***********************************************************///************** IIS控制管理类 1.0 Beta ** ...

  3. Kafka 之 async producer (2) kafka.producer.async.DefaultEventHandler

    上次留下来的问题 如果消息是发给很多不同的topic的, async producer如何在按batch发送的同时区分topic的 它是如何用key来做partition的? 是如何实现对消息成批量的 ...

  4. CentOS SSH安装与配置

    SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议. 传 统的网络服务程序, ...

  5. Eclipse如何导出可执行jar包

    在编写shell脚本时用到了可执行的jar包,而jar包从Eclipse中导出时需要同时导出jar文件以及库文件夹,具体导出方式如下: (1)点击主方法所在的java,运行java applicati ...

  6. 重载操作符 operator overloading 学习笔记

    重载操作符,只是另外一种调用函数的方法和表现方式,在某些情况它可以让代码更简单易读.注意不要过度使用重载操作符,除非它让你的类更简单,让你的代码更易读. 1语法 如下: 其中友元,关键字不是必须的,但 ...

  7. php/ java/asp.net

    php大型网站用得多 企业级开发 java/asp.net用得多 这个很好理解 php 执行效率好 可塑性强 接近底层 java asp.net 封装了更多的东西,开发企业级业务 效率更高, 但是高性 ...

  8. java网络基本类使用(一)

    1.怎么获取ip相关信息 import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumera ...

  9. Redpine Signals RS9110-N-11-02 Wi-Fi解决方案

    Redpine Signals公司的RS9110-N-11-02是兼容IEEE 802.11bgn的Wi-Fi客户端模块,集成了MAC,基带处理器,RF收发器和功率放大器.和RS9110-LI MAC ...

  10. echarts入门,5分钟上手写ECharts的第一个图表

    1.新建一个echarts.html文件,为ECharts准备一个具备大小(宽高)的Dom. <!DOCTYPE html> <head> <meta charset=& ...