题目大意:

铁人三项分连续三段:游泳 自行车 赛跑

已知各选手在每个单项中的速度v[i],u[i],w[i]

设计每个单项的长度 可以让某个特定的选手获胜

判断哪些选手有可能获得冠军

输出n行 有可能获得冠军为Yes 不可能为No

设赛程总长为1,游泳x 自行车y,则赛跑为1-x-y

若选手 i 可以打败选手 j 则

x / v[ i ] + y / u[ i ] + ( 1-x-y ) / w[ i ] < x / v[ j ] + y / u[ j ] + ( 1-x-y ) / w[ j ]

整理成 a*x+b*y+c >0 的形式 那么得到

a = ( 1 / v[ j ] - 1 / w[ j ] ) - ( 1 / v[ i ] - 1 / w[ i ] )

b = ( 1 / u[ j ] - 1 / w[ j ] ) - ( 1 / u[ i ] - 1 / w[ i ] )

c = 1 / w[ j ] - 1 / w[ i ]

最后加上三个固定约束

x > 0 , y > 0 , 1 - x - y > 0

只要 i 与其他所有 j 存在满足的解 就为Yes

#include <bits/stdc++.h>
using namespace std; const double eps=1e-;
double add(double a,double b) {
if(abs(a+b)<eps*(abs(a)+abs(b))) return ;
return a+b;
}
struct P {
double x,y;
P(){}
P(double _x,double _y):x(_x),y(_y){}
P operator - (P p) {
return P(add(x,-p.x),add(y,-p.y)); }
P operator + (P p) {
return P(add(x,p.x),add(y,p.y)); }
P operator / (double d) {
return P(x/d,y/d); }
P operator * (double d) {
return P(x*d,y*d); }
double dot (P p) {
return add(x*p.x,y*p.y); }
double det (P p) {
return add(x*p.y,-y*p.x); }
void read(){
scanf("%lf%lf",&x,&y); }
};
struct L {
P p,v;
double ang;
L(){}
L(P _p,P _v):p(_p),v(_v){ ang=atan2(v.y,v.x); }
bool operator < (const L& b)const {
return ang<b.ang;
}
}l[];
int v[],u[],w[];
int n, cnt; bool onLeft(L l,P p) {
return (l.v).det(p-l.p)>;
} /// p在l的左边
P ins(L a,L b) {
return a.p+a.v*((b.v).det(a.p-b.p)/(a.v).det(b.v));
} /// a与b的交点
int insHp() {
sort(l,l+cnt); vector <P> pi(*cnt);
vector <L> li(*cnt);
int head,tail;
li[head=tail=]=l[];
for(int i=;i<cnt;i++) {
while(head<tail && !onLeft(l[i],pi[tail-])) tail--;
while(head<tail && !onLeft(l[i],pi[head])) head++;
li[++tail]=l[i]; if(abs((li[tail].v).det(li[tail-].v))<eps) {
tail--;
if(onLeft(li[tail],l[i].p)) li[tail]=l[i];
}
if(head<tail) pi[tail-]=ins(li[tail],li[tail-]);
}
while(head<tail && !onLeft(li[head],pi[tail-])) tail--; if(tail-head<=) return ;
pi[tail]=ins(li[tail],li[head]); return tail-head+;
} /// 半平面交 返回最后得到的多边形的顶点数 void solve() {
for(int i=;i<n;i++) {
cnt=;
bool ok=;
double k=; /// 数据范围来说 设k=10000 for(int j=;j<n;j++) {
if(i==j) continue;
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; /// 必胜
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]; /// 数值过小会产生精度误差
P v=P(b,-a);
if(abs(a)>abs(b)) l[cnt]=L(P(-c/a,),v);
else l[cnt]=L(P(,-c/b),v);
cnt++;
}
if(ok) {
l[cnt++]=L(P(,),P(,-));
l[cnt++]=L(P(,),P(,));
l[cnt++]=L(P(,),P(-,)); // 三个固定约束
if(!insHp()) ok=; // 半平面交无解 说明必败
}
if(ok) printf("Yes\n");
else printf("No\n");
}
} int main()
{
while(~scanf("%d",&n)) {
for(int i=;i<n;i++)
scanf("%d%d%d",&v[i],&u[i],&w[i]);
solve();
} return ;
} //

LA2218 Triathlon /// 半平面交 oj22648的更多相关文章

  1. POJ 1755 Triathlon [半平面交 线性规划]

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6912   Accepted: 1790 Descrip ...

  2. LA 2218 Triathlon(半平面交)

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

  3. POJ 1755 Triathlon (半平面交)

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4733   Accepted: 1166 Descrip ...

  4. POJ 1755 Triathlon(线性规划の半平面交)

    Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...

  5. LA 2218 (半平面交) Triathlon

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

  6. poj 1755 半平面交+不等式

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6461   Accepted: 1643 Descrip ...

  7. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  8. 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分

    2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 959  Solved: 489[Submit][Status] ...

  9. 【CSU1812】三角形和矩形 【半平面交】

    检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...

随机推荐

  1. linux基础知识汇总(四)--ps grep命令

    转:http://www.cnblogs.com/allen8807/archive/2010/11/10/1873843.html http://www.cnblogs.com/end/archiv ...

  2. codeforces 447E or 446C 线段树 + fib性质或二次剩余性质

    CF446C题意: 给你一个数列\(a_i\),有两种操作:区间求和:\(\sum_{i=l}^{r}(a[i]+=fib[i-l+1])\).\(fib\)是斐波那契数列. 思路 (一) codef ...

  3. 输入流当中的read方法和readfully方法的区别与原理

    原文链接:https://blog.csdn.net/yangjingyuan/article/details/6151234?locationNum=3 DataInputStream类中的read ...

  4. HTML a标签文字颜色

    1.css代码: a{color:#00F} a:hover{color:#f00}/* 鼠标经过悬停字体颜色 */ /* css 注释说明:以上代码为设置HTML中超链接统一字体颜色 */ .div ...

  5. Linux apache httpd virtual配置

    必须要关闭 selinux,否则无法访问目录

  6. UI自动化ADB出现devices offline的解决方法

    终端运行如下命令即可解决: adb kill-server adb start-server adb remount

  7. violet

    操作系统的发展史 1.穿孔卡片 一个计算机机房一次只能被一个卡片使用 缺点:cpu的利用率低 2.联机批处理系统 支持多用户去使用一个计算机机房 3.脱机批处理系统 告诉磁盘 提高文件的读取速度 优点 ...

  8. 22-4-isarry

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. mysql数据库 --数据类型、约束条件

    今日内容 表的详细使用 1.创建表的完成语法 2.字段类型 整型.浮点型.字符类型.日期类型.枚举与集合类型 3.约束条件 primary key.unique.not null.default 一. ...

  10. 2019-5-16-WPF-光标初始化的时候-temp-文件夹满了无法创建

    title author date CreateTime categories WPF 光标初始化的时候 temp 文件夹满了无法创建 lindexi 2019-05-16 19:16:27 +080 ...