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 ...
随机推荐
- c++的格式控制
1: 每个iostream对象维持一个控制IO格式化细节的格式状态.标准库定义了一组操纵符来修改对象的格式状态.所谓操纵符是可用作输入或输出操作符的函数或对象.iostream和iomanip头文件中 ...
- qt打包问题。启动失败:Application failed to start because platform plugin “windows” is missing
qt打包启动失败:Application failed to start because platform plugin “windows” is missing 通常的原因是因为没有platform ...
- 使用IDEA整合SSM框架
一.安装环境和开发工具 在整合Spring,SpringMVC 和 MyBatis 的过程中,很容易遇到一些小问题,因此记录下整合过程. 首先是安装环境和开发工具,如下: Window 7 Jdk 1 ...
- RN项目中缩进处理
SpannableString使用详解http://blog.csdn.net/u012702547/article/details/49895157 Spannable的用法http://www.j ...
- ARM协处理器CP15寄存器详解【转】
本文转载i自;https://blog.csdn.net/gameit/article/details/13169405 用于系统存储管理的协处理器CP15 MCR{cond} copro ...
- Spring AOP(3)
- java基础(6)--数组和方法
数组 1. 什么是数组? 数组是相同数据类型的元素组成的集合.这些元素按线性顺序排列.所谓线性顺序是指除第一个元素外,每一个元素都有唯一的前驱元素:除最后一个元素外,每一个元素都有唯一的后继元素.(“ ...
- http 和 soap 关系 - 转载
http soap关系 HTTP http:是一个客户端和服务器端请求和应答的标准(TCP).http协议其目的是为了提供一种发布和接收htttp页面的方法 一http协议的客户端与服务器的交互:由H ...
- ActiveMQ_01
http://shhyuhan.iteye.com/blog/1278103http://www.cnblogs.com/blsong/archive/2012/09/26/2704337.htmlh ...
- css类名大全以及其他关键词
标签 abbr 缩写的标记 token-based-auth-backend 后端 token-based-auth-frontend 前端 signin 登陆 Sign in / Sign u ...