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 ...
随机推荐
- 如何控制iOS的导航栏和状态栏的样式
这是一个很常用的开发场景,就是改变导航栏上的文字颜色与背景色,如果你曾有 windows form 开发经验一定会笑我:"卧槽,这有什么好写的,不就是设置两个属性就可以了吗?" 我 ...
- TensorFlow训练MNIST数据集(3) —— 卷积神经网络
前面两篇随笔实现的单层神经网络 和多层神经网络, 在MNIST测试集上的正确率分别约为90%和96%.在换用多层神经网络后,正确率已有很大的提升.这次将采用卷积神经网络继续进行测试. 1.模型基本结构 ...
- MODIS 数据产品预处理
MODIS 数据产品预处理 1 MCTK重投影 第一步:安装ENVI的MCTK扩展工具 解压压缩包,将其中的mctk.sav与modis_products.scsv文件复制到如图所示,相应的ENVI ...
- CoreDNS Plugins ---> hosts
需求 kubernetes集群外部有少量服务,kubernetes集群内部pod需要通过服务所在的主机的hostname访问服务. 解决方案 通过coredns的hosts插件配置kubernetes ...
- 软工团队(hello world)组员介绍
姜中希:喜欢编程,善于交际. 周盼超:喜欢编程. 王昭博:思路比较清晰,可以明确开发步骤. 刘洪阳:思想笔记广泛,可以把很多有关联的东西结合起来. 刘双勃:喜欢编程,踏实,比较容易坚持.
- Four-Operations
开发环境:Eclipse 结对小伙伴:201306114416 陈键 (http://www.cnblogs.com/be-the-one/) 201306114452 吴舒婷 (http://www ...
- Beta阶段 冲刺博客合集
一.Beta阶段敏捷冲刺前准备 二.Beta阶段敏捷冲刺① 三.Beta阶段敏捷冲刺② 四.Beta阶段敏捷冲刺③ 五.Beta阶段敏捷冲刺④ 六.Beta阶段敏捷冲刺⑤ 七.用户使用调查报告 八.码 ...
- 『编程题全队』Beta 阶段冲刺博客集合
『编程题全队』Beta 阶段冲刺博客集合 »敏捷冲刺 日期:2018.5.23 博客连接:『编程题全队』Scrum 冲刺博客 »Day1 日期:2018.5.23 博客连接:『编程题全队』Beta 阶 ...
- 【补】debug
懒得翻别人博客了,之前的按钮不显示名字,应该是文字ui文件名写错了. 现在不存在任何已知bug.
- php环境搭建及入门
在php文件里,写入header('content-type:text/html;charset = uft-8'); <?php header('content-type:text/html; ...