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 ...
随机推荐
- 四:RF框架appium工具之xpath定位
XPATH定位方法具体的学会,还是在今年1月份,以前运用的都不熟练. 这个定位神器是一定要掌握的,不然有你抓狂的时候. 第一要掌握它的书写格式,这个好上手. 第二要掌握它的具体用法.这个就要多练习了, ...
- ASP.NET Core学习——2
Application Startup ASP.NET Core为应用程序提供了处理每个请求的完整控制.Startup类是应用程程的入口(entry point),这个类可以设置配置(configur ...
- 模拟栈&&模拟队列
模拟栈:class Stack { private List list = new ArrayList( ); public void push( Object obj ) { this.list.a ...
- spark hive java.lang.NoSuchFieldError: HIVE_STATS_JDBC_TIMEOUT
java.lang.NoSuchFieldError: HIVE_STATS_JDBC_TIMEOUT 这个问题我感觉是hive给spark挖的一个大坑.spark版本是2.4.4,hive是3 这个 ...
- MySQL之explain命令解释
explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了.如: explai ...
- 【react】---Hooks的基本使用---【巷子】
一.react-hooks概念 React中一切皆为组件,React中组件分为类组件和函数组件,在React中如果需要记录一个组件的状态的时候,那么这个组件必须是类组件.那么能否让函数组件拥有类组件的 ...
- firewall防火墙配置
获取所有zone firewall-cmd --list-all-zones 重启服务 firewall-cmd --complete-reload 名词解释 在具体介绍zone之前学生先给大家介绍几 ...
- python软件开发规范&分文件对于后期代码的高效管理
根据本人的学习,按照理解整理和补充了python模块的相关知识,希望对于一些需要了解的python爱好者有帮助! 一.软件开发规范--分文件 当代码存在一个py文件中时: 1.不便于管理 (修改,增加 ...
- locust性能测试框架随笔
现在有很多的性能测试工具,比如说我们熟悉的loadrunner.jmeter.ab.webbench等等,这些工具如果对一个没用过的朋友来说,学习起来比较不容易,但是如果你能看懂python代码,会写 ...
- 要素选择变化事件 IActiveViewEvents_SelectionChanged
void IDockableWindowDef.OnCreate(object hook) { m_application = hook as IApplication; m_hookHelper = ...