LA2218 Triathlon
题意
分析
设出长度\(x,y,1-x-y\),就是关于它们的二元一次不等式,判断有没有解。
可以用半平面交来解决。
x/V[i]+y/U[i]+(1-x-y)/W[i] < x/V[j]+y/U[j]+(1-x-y)/W[j]
ax+by+c>0
然后关于这些不等式似乎只能先化为我所熟悉的\(y=kx+b\)然后再做?我没有想出更好的解决方法。
枚举每一个点再枚举点集,时间复杂度\(O(T n^2 \log n)\)
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll;
struct Point
{
double x,y;
Point(double x=0,double y=0)
:x(x),y(y){}
};
typedef Point Vector;
Vector operator+(co Vector&A,co Vector&B)
{
return Vector(A.x+B.x,A.y+B.y);
}
Vector operator-(co Vector&A,co Vector&B)
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator*(co Vector&A,double p)
{
return Vector(A.x*p,A.y*p);
}
double Dot(co Vector&A,co Vector&B)
{
return A.x*B.x+A.y*B.y;
}
double Cross(co Vector&A,co Vector&B)
{
return A.x*B.y-A.y*B.x;
}
double Length(co Vector&A)
{
return sqrt(Dot(A,A));
}
Vector Normal(co Vector&A)
{
double L=Length(A);
return Vector(-A.y/L,A.x/L);
}
double PolygonArea(vector<Point>p)
{
int n=p.size();
double area=0;
for(int i=1;i<n-1;++i)
area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
}
struct Line
{
Point P;
Vector v;
Line(Point P=0,Vector v=0)
:P(P),v(v){}
double angle()co
{
return atan2(v.y,v.x);
}
bool operator<(co Line&rhs)co
{
return angle()<rhs.angle();
}
};
bool OnLeft(co Line&L,co Point&p)
{
return Cross(L.v,p-L.P)>0;
}
Point LineLineIntersection(co Line&a,co 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;
}
co double eps=1e-6;
vector<Point>HalfplaneIntersection(vector<Line>L)
{
int n=L.size();
sort(L.begin(),L.end());
int first,last;
vector<Point>p(n);
vector<Line>q(n);
vector<Point>ans;
q[first=last=0]=L[0];
for(int i=1;i<n;++i)
{
while(first<last&&!OnLeft(L[i],p[last-1]))
--last;
while(first<last&&!OnLeft(L[i],p[first]))
++first;
q[++last]=L[i];
if(fabs(Cross(q[last].v,q[last-1].v))<eps)
{
--last;
if(OnLeft(q[last],L[i].P))
q[last]=L[i];
}
if(first<last)
p[last-1]=LineLineIntersection(q[last-1],q[last]);
}
while(first<last&&!OnLeft(q[first],p[last-1]))
--last;
if(last-first<=1)
return ans;
p[last]=LineLineIntersection(q[last],q[first]);
for(int i=first;i<=last;++i)
ans.push_back(p[i]);
return ans;
}
co int N=100;
int V[N],U[N],W[N];
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;++i)
{
read(V[i]);read(U[i]);read(W[i]);
}
for(int i=0;i<n;++i)
{
bool ok=1;
double k=1e4;
vector<Line>L;
for(int j=0;j<n;++j)
if(i!=j)
{
if(V[i]<=V[j]&&U[i]<=U[j]&&W[i]<=W[j])
{
ok=0;
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,0);
else
P=Point(0,-c/b);
L.push_back(Line(P,v));
}
if(ok)
{
L.push_back(Line(Point(0,0),Vector(0,-1)));
L.push_back(Line(Point(0,0),Vector(1,0)));
L.push_back(Line(Point(0,1),Vector(-1,1)));
vector<Point>poly=HalfplaneIntersection(L);
if(poly.empty())
ok=0;
}
puts(ok?"Yes":"No");
}
}
return 0;
}
LA2218 Triathlon的更多相关文章
- LA2218 Triathlon /// 半平面交 oj22648
题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...
- 铁人系列(2)LA2218
思路:对于每个人 都会有n-1个半片面 加上x>0,y>0,1-x-y>0(这里的1抽象为总长) 代码是粘贴的 原来写的不见了 orz............ // LA22 ...
- 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匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...
- uva 2218 Triathlon
题意:铁人三项赛,给定每个选手游泳,自行车,赛跑三个阶段的平均速度,不知道每段比赛的路程,询问当前这个选手能否胜利. 思路:把题意转化为一个不等式,设比赛长度是1,如果i要战胜j,x.y分别是第一阶段 ...
- uva 1298 - Triathlon
半平面交的题: 这个题目的亮点就是建模: #include<cstdio> #include<algorithm> #include<cmath> #define ...
随机推荐
- python数据可视化(持续更新)
1.折线图 import numpy as np import matplotlib.pyplot as plt input_values = [1, 2, 3, 4, 5] s = [1, 4, 9 ...
- Shell awk 求标准差
cat > temp000180255798957892187719 awk '{x[NR]=$0; s+=$0; n++} END{a=s/n; for (i in x){ss += (x[i ...
- 完全理解Android中的RemoteViews
一.什么是RemoteViews RemoteViews翻译过来就是远程视图.顾名思义,RemoteViews不是当前进程的View,是属于SystemServer进程.应用程序与RemoteView ...
- 内存中加载DLL DELPHI版
//从内存中加载DLL DELPHI版 unit MemLibrary; interface uses Windows; function memLoadLibrary(pLib: Pointer): ...
- scjp考试准备 - 10 - 类型转换
题目为如下代码的执行结果: class Building{} public class Barn extends Building{ public static void main(String[] ...
- Mysql 索引复习笔记
之前学习索引后由于一直没怎么用,所以也只是粗略看了一下,最近发现索引的用处很大,并且也很多知识点,在此做复习记录. 什么是索引? 百度百科是这样描述的: 索引是为来加速对表中数据行中的检索而创建的一种 ...
- HTML5 ——web audio API 音乐可视化(一)
使用Web Audio API可以对音频进行分析和操作,最终实现一个音频可视化程序. 最终效果请戳这里; 完整版代码请戳这里,如果还看得过眼,请给一个start⭐ 一.API AudioContext ...
- 深入理解Lambda
概述 Lambda是一个表达式,也可以说它是一个匿名函数.然而在使用它或是阅读Lambda代码的时候,却显得并不那么容易.因为它匿名,因为它删减了一些必要的说明信息(比如方法名).下面就来说说Lamb ...
- Ubuntu chrome FQ
按照文档FQ,需要注意一下两点: 1. 在安装Chrome 下的 SwitchyOmega 插件时,拖入到浏览器不能识别,应该打开chrome://extensions/再拖入: 2.在设置时排列列表 ...
- Ceph Monitor的数据管理
转自:https://www.ustack.com/blog/ceph-monitor-2/ Monitor管理了Ceph的状态信息,维护着Ceph中各个成员的关系,这些信息都是存放在leveldb中 ...