uva 2218 Triathlon
题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利。
思路:把题意转化为一个不等式,设比赛长度是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的更多相关文章
- LA 2218 Triathlon(半平面交)
Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...
- uva 1298 - Triathlon
半平面交的题: 这个题目的亮点就是建模: #include<cstdio> #include<algorithm> #include<cmath> #define ...
- UVALive 2218 Triathlon
https://vjudge.net/problem/UVALive-2218 题意: 铁人三项比赛,每项比赛长度未定,已知每个选手每项比赛的平均速度. 设计每项比赛的长度,让其中某个特定选手获胜. ...
- LA 2218 (半平面交) Triathlon
题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
随机推荐
- MySQL查询本周、上周、本月、上个月份数据的sql代码(转)
感谢:http://www.jb51.net/article/32277.htm ----------------------------------------------------------- ...
- Hibernate缓存机制简述 (转)
感谢:http://blog.csdn.net/ramln1989/article/details/5528445 ------------------------------------------ ...
- json2.js使用参考
json2.js的源码地址: https://github.com/douglascrockford/JSON-js Visual Studio用户可以直接通过Nuget来获得. json2.js提供 ...
- [转载]jQuery.lazyload详解 - 图片延时加载
jQuery实现图片延迟加载,不知道是否可以节省带宽呢?有人知道吗? 这究竟只是一个视觉特效还是真的能延迟加载减少服务器的请求呢? <script type="text/javascr ...
- 快速配置Ehcache
1. 编写ehcache.xml文件,将该文件放置于classpath路径下.代码如下: <?xml version="1.0" encoding="UTF-8&q ...
- RASP 完爆 WAF 的5大理由!
Web 应用防火墙(WAF)已经成为常见 Web 应用普遍采用的安全防护工具,即便如此,WAF 提供的保护方案仍旧存在诸多不足,笔者认为称 WAF 为好的安全监控工具更为恰当.幸运的是,应用安全保护技 ...
- 【形式化方法:VDM++系列】2.VDMTools环境的搭建
接前文:http://www.cnblogs.com/Kassadin/p/3975853.html 上次讲了软件需求分析的演化过程,本次进入正题——VDM开发环境的搭建 (自从发现能打游戏以来,居然 ...
- linux useradd添加用户
useradd命令用来建立用户帐号和创建用户的起始目录,使用权限是超级用户. useradd -m -s /bin/bash -g 群组名 用户名 其中 -m:自动建立用户的登入目录. -s:指定用户 ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-004-对密码加密passwordEncoder
一. 1.Focusing on the authentication query, you can see that user passwords are expected to be stored ...
- Linux的分段和分页机制
1.分段机制 80386的两种工作模式 80386的工作模式包括实地址模式和虚地址模式(保护模式).Linux主要工作在保护模式下. 分段机制 在保护模式下,80386虚地址空间可达16K个段,每 ...