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 ...
随机推荐
- Linux环境进程间通信----系统 V 消息队列(二)
一.消息队列是一条由消息连接而成的链表,它保存在内核中,通过消息队列的引用标示符来访问. 二.消息队列不同于管道,通信的两个进程可以是完全无关的进程,它们之间不需要约定同步的方法.只要消息队列存在并且 ...
- “今日头条杯”首届湖北省大学程序设计竞赛--F. Flower Road
题目链接:点这 github链接:(包含数据和代码,题解):点这 链接:https://www.nowcoder.com/acm/contest/104/E来源:牛客网 题目描述 (受限于评测机,此题 ...
- Hdu-4757 Tree(可持久化字典树+lca)
题目链接:点这 我的github地址:点这 Problem Description Zero and One are good friends who always have fun wi ...
- share memory
header for public argument:shmdata.h #define TEXT_SZ 2048 struct shared_use_st { int written; char t ...
- 【linux】netlink
Netlink实现网卡上下线监控 https://blog.csdn.net/sourthstar/article/details/7975999
- 解决Python报错:local variable 'xxx' referenced before assignment(引)
解决Python报错:local variable 'xxx' referenced before assignment(引) 解决Python报错:local variable 'xxx' refe ...
- Java学习之DOS基础
Dos命令行dir:列出当前目录下的文件和文件夹md :创建目录rd :删除目录cd :进入指定目录cd..:退回到上一级目录cd/:退回到根目录del:删除文件exit:退出dos命令行 进入dos ...
- pair的用法
如何定义?(初始化) 1. pair<int,int>p; 2.定义即初始化,也可以这个样子 pair<,); 里面的类型还可以是string,double等. 3.还可以这样子初始 ...
- HDU 6659 Acesrc and Good Numbers (数学 思维)
2019 杭电多校 8 1003 题目链接:HDU 6659 比赛链接:2019 Multi-University Training Contest 8 Problem Description Ace ...
- Java 并发之原子性与可见性
原子性 原子是世界上的最小单位,具有不可分割性.比如 a=0:(a非long和double类型) 这个操作是不可分割的,那么我们说这个操作时原子操作.再比如:a++: 这个操作实际是a = a + 1 ...