LA2218 Triathlon /// 半平面交 oj22648
题目大意:
铁人三项分连续三段:游泳 自行车 赛跑
已知各选手在每个单项中的速度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的更多相关文章
- POJ 1755 Triathlon [半平面交 线性规划]
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6912 Accepted: 1790 Descrip ...
- LA 2218 Triathlon(半平面交)
Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...
- POJ 1755 Triathlon (半平面交)
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4733 Accepted: 1166 Descrip ...
- POJ 1755 Triathlon(线性规划の半平面交)
Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...
- LA 2218 (半平面交) Triathlon
题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...
- poj 1755 半平面交+不等式
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6461 Accepted: 1643 Descrip ...
- 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)
按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...
- 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分
2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 959 Solved: 489[Submit][Status] ...
- 【CSU1812】三角形和矩形 【半平面交】
检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...
随机推荐
- 如何在普通用户权限cmd怎么使用命令行变为管理员权限
这两天在弄MySql,由于我下载的是免安装版本,环境自己配置了一下.有强迫症不喜欢某些服务打开在我不需要的时候,我一般都设置为手动,但是每次使用数据库时都要使用net start mysql启动MyS ...
- Navicat for MySQL使用手记
摘要 在管理MySQL数据库的图形化工具中,最为熟知的就是phpMyAdmin和Mysql-Front了,今天跟大家分享另外一个管理mysql数据库的另外一个利器---Navicat MySQL. N ...
- mysql高效导入导出load data [infile][outfile]用法
一.MySQL高效导入数据的方法load data infile load data infile语句从一个文本文件中以很高的速度读入一个表中.使用这个命令之前,mysqld进程(服务)必须已经在运行 ...
- background-size的值cover、contain和100%
图1 给一个宽600px,高600px的div添加一张宽480px,高360px的背景图片.不重复显示的情况下,默认显示为图1. 1.background-size: 100% 100%; 会将图片的 ...
- Excel函数——ANSI字符集与Code、Char、Asc函数
小叙背景 Windows系统下,默认的字符集为ANSI,该字符编码方式在不同语言环境下采用不同的编码方案,在中文系统下ANSI编码是GBK.ANSI由ASCII扩展而来,ANSI下无论何种具体的编码方 ...
- PHP操作XML方法之SimpleXML
SimpleXML简介 SimpleXML 扩展提供了一个非常简单和易于使用的工具集,能将XML转换成一个带有一般属性选择器和数组迭代器的对象. 举例XML XML结构部分引用自<<深入理 ...
- JavaScript中的面向对象编程,详解原型对象及prototype,constructor,proto,内含面向对象编程详细案例(烟花案例)
面向对象编程: 面向:以什么为主,基于什么模式 对象:由键值对组成,可以用来描述事物,存储数据的一种数据格式 编程:使用代码解决需求 面向过程编程: 按照我们分析好的步骤,按步 ...
- 21-7-数组相关api
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 在KVM虚拟化中如何实现vlan
换了好几个浏览器,都不能复制文字上来,不知道为什么.就发我的笔记截图吧
- 随笔记录 shell脚本相关内容 2019-8-26
字符串截取: 假设变量为var=http://www.hao.com/123.htm1. # 号截取,删除左边字符,保留右边字符.echo ${var#*//}其中 var 是变量名,# 号是运算符, ...