UVALive 2218 Triathlon
https://vjudge.net/problem/UVALive-2218
题意:
铁人三项比赛,每项比赛长度未定,已知每个选手每项比赛的平均速度。
设计每项比赛的长度,让其中某个特定选手获胜。
判断哪些选手有可能 获得冠军,并列不算
每项比赛长度必须>0
线性规划问题
设比赛总长度为1,第一项长度为x,第二项长度为y,第三项长度为1-x-y
则选手i打败选手j的条件是

化为Ax+By+C>0,得



对于每个选手i,都会得到n-1个半平面
再加上x>0,y>0,1-x-y>0
一共n+2个半平面
如果这n+2个半平面有交,那么选手i可能获得冠军
#include<cmath>
#include<cstdio>
#include<algorithm> #define N 104 using namespace std; const double eps=1e-; struct Point
{
double x,y; Point(double x=,double y=) : x(x),y(y) { } }; typedef Point Vector; Vector operator + (Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y); }
Vector operator - (Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }
Vector operator * (Vector A,double b) { return Vector(A.x*b,A.y*b); } 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 < (Line L) const
{
return ang<L.ang;
}
}; Line L[N]; double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
} bool OnLeft(Line L,Point p)
{
return Cross(L.v,p-L.P)>;
} Point GetIntersection(Line a,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;
} bool HalfplaneIntersection(Line *L,int n)
{
sort(L,L+n);
int first,last;
Point *p=new Point[n];
Line *q=new Line[n];
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-]=GetIntersection(q[last-],q[last]);
}
while(first<last && !OnLeft(q[first],p[last-])) last--;
return last-first>;
} int V[N],U[N],W[N]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;++i) scanf("%d%d%d",&V[i],&U[i],&W[i]);
for(int i=;i<n;++i)
{
int lc=; bool ok=true;
double k=;
for(int j=;j<n;++j)
if(i!=j)
{
if(V[i]<=V[j] && U[i]<=U[j] && W[i]<=W[j]) { ok=false; break; }
if(V[i]>=V[j] && U[i]>=U[j] && W[i]>=W[j]) continue;
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[lc++]=Line(P,v);
}
if(ok)
{
L[lc++]=Line(Point(,),Vector(,-));
L[lc++]=Line(Point(,),Vector(,));
L[lc++]=Line(Point(,),Vector(-,));
if(!HalfplaneIntersection(L,lc)) ok=false;
}
puts(ok ? "Yes" : "No");
}
}
}
UVALive 2218 Triathlon的更多相关文章
- LA 2218 Triathlon(半平面交)
Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...
- uva 2218 Triathlon
题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利. 思路:把题意转化为一个不等式,设比赛长度是1,如果i要战胜j,x.y分别是第一阶段 ...
- LA 2218 (半平面交) Triathlon
题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
随机推荐
- ECC检验与纠错
引入ECC ECC:Error Checking and Correction,是一种差错检测和修正的算法. NAND闪存在生产和使用中都会有坏块产生,BBM就是坏块的管理机制.而生产坏块已经无法避免 ...
- UE4添加植被Foliage Type
在UE4中的地形渲染上不可避免的需要添加植被,而如果采取手动添加StaticMesh植被的方式则会浪费大量的时间精力. UE4提供了一种批量添加地面植被类型的方式Foliage Type.在编辑器内容 ...
- 作业三:LINUX内核的启动过程
作业三:LINUX内核的启动过程 一.使用GDB跟踪内核从start_kernel到init进程启动(附实验截图) (一)使用自己的Linux系统环境搭建MenuOS的过程 下载内核源代码编译内核 c ...
- week4
History:Commercialization and Growth course Explosive Growth of the Internet and Web The Year of the ...
- Linux命令(四)删除文件 rm
用户可以使用 rm 命令删除不需要的文件. rm 可以删除文件或目录,并且支持通配符. 如果目录中存在其它文件则会递归删除. 删除软链接只是删除链接,对应的文件或目录不会被删除. 软链接类似于 win ...
- git 客户端连接gitlab 实现简单的CI/CD
1. git 客户端的安装 下载: https://git-scm.com/download/win 截至最近:20180728最新版本 2.18的下载地址 https://github-produc ...
- Git从零开始(一)
一.首先windows安装git客户端 官网下载地址:https://git-for-windows.github.io/,这里下载会很慢,我试了好几次都失败了. 百度网盘资源: https://pa ...
- python基础教程1:入门基础知识
写在系列前,一点感悟 没有梳理总结的知识毫无价值,只有系统地认真梳理了才能形成自己的知识框架,否则总是陷入断片儿似的学习-遗忘循环中. 学习方法真的比刻苦"傻学"重要多了,而最重要 ...
- wireshark系列之wireshark过滤器
一:过滤器 使用wireshark工具抓包,如果使用默认配置,会得到大量的数据,所以我们就很难找到我们要分析的封包数据.所以使用wireshark过滤器就显得尤为重要. wireshark过滤器分为两 ...
- JIRA状态为任务结束,但是解决结果为未解决相关配置
1.JIRA状态为任务结束,但是解决结果为未解决,如下图所示: 2.在工作流->界面->结果处理中进行解决结果的配置(首先确保界面配置中有“解决结果”字段). 3.点击“结果处理”,进行结 ...