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 ...
随机推荐
- JavaScript快速入门-DOM对象
一.概述 1.什么是 DOM? DOM 是 W3C(万维网联盟)的标准.DOM 定义了访问 HTML 和 XML 文档的标准: "W3C 文档对象模型(DOM)是中立于平台和语言的接口,它允 ...
- NAND Flash底层原理,SLC MLC TLC比较
NAND-Flash 的存储原理 固态硬盘最小单元的基本架构如下: 我们知道计算机中所有的信息储存最终都必须回归到 0与1,原则上,只要存储单元能提供两种或两种以上可供辨识的状态,便可以拿来纪录数据. ...
- GPT & UEFI Install Windows7
安装介质以FAT或者FAT32分区安装介质添加UEFI支持文件(Windows7及其以前的系统,不支持UEFI启动) 从Windows8的安装文件中提取Bootmgfw.efi文件,重命名为BOOTX ...
- 【zigbee 】2.4G信号发放器 AT2401C PA功放
概述 AT2401C 是一款面向Zigbee,无线传感网络以及其他2.4GHz 频 段无线系统的全集成射频功能的射频前端单芯片.AT2401C 是采用 CMOS 工艺实现的单芯片器件,其内部集成了功率 ...
- Mac OS系统四种修改Hosts文件的方法列举
转自:https://blog.csdn.net/u012460084/article/details/40186973 使用Mac OS X系统的用户,在某些时候可能遇到了需要修改系统Hosts文件 ...
- PAT甲题题解-1091. Acute Stroke (30)-BFS
题意:给定三维数组,0表示正常,1表示有肿瘤块,肿瘤块的区域>=t才算是肿瘤,求所有肿瘤块的体积和 这道题一开始就想到了dfs或者bfs,但当时看数据量挺大的,以为会导致栈溢出,所以并没有立刻写 ...
- js分页实例
js分页实例 案例1 1.js_pageusers.html <!DOCTYPE html> <html> <head> <title>js_pageu ...
- “数学口袋精灵”第二个Sprint计划---第一天
“数学口袋精灵”第二个Sprint计划----第一天进度 任务分配: 冯美欣:欢迎界面的音效 吴舒婷:游戏界面的动作条,选择答案后的音效 林欢雯:完善算法代码的设计 进度: 冯美欣:上网百度音乐资 ...
- 关于Win10系统下VC2013安装Unit test出现问题的解决办法
话不多说,先上图~~~ 很多同学在Vs2013安装Unit test组件时会弹出这样的对话框,极其极其让人崩溃. 当我看到这个对话框时,首先中规中矩的去官网下载.NET(但是我怎么可能没有!游戏环境包 ...
- 2017-08-20 block,inline和inline-block概念和区别
display:inline.block.inline-block的区别 display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都 ...