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 ...
随机推荐
- Nginx URL跳转
配置需求 注:$document_uri 表示访问的url 需求:访问 www.abc.com 请求到 www.abc.com/abc/ 使用操作 1.在nginx配置文件中加入 if ($doc ...
- CSS 3 中的多列属性
.column-count <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- HTML5抽奖转盘
在线演示 本地下载
- c刷新缓冲区
int c; while((c = getchar()) != '\n' && c != EOF);
- AndroidDevTools下载
收集整理Android开发所需的Android SDK.开发中用到的工具.Android开发教程.Android设计规范,免费的设计素材等. http://www.androiddevtools.cn ...
- Docker在渗透中的应用
起因 环境因素影响,我他么路由器映射端口 msf就是反弹不回来session,在跟大牛交流后,大牛说服务器装个kali就行了,我以为是叫idc那边直接安装,但是因为这个系统特殊,很多 idc不允许安装 ...
- CODE FESTIVAL 2015 決勝(部分)
CODE FESTIVAL 2015 決勝(部分) B - ダイスゲーム 题意: 给\(N\)个\(6\)个面骰子,然后问掷到概率最大的点数是多少. 分析: 随便打表随便发现是\(\huge\left ...
- [Ctsc2000]冰原探险
Description 传说中,南极有一片广阔的冰原,在冰原下藏有史前文明的遗址.整个冰原被横竖划分成了很多个大小相等的方格.在这个冰原上有N个大小不等的矩形冰山,这些巨大的冰山有着和南极一样古老的历 ...
- 未来简史之数据主义(Dataism)
https://www.jianshu.com/p/8147239c9cb0?from=singlemessage junjguo 关注 2017.04.24 22:08* 字数 8116 阅读 31 ...
- Substring with Concatenation of All Words, 返回字符串中包含字符串数组所有字符串元素连接而成的字串的位置
问题描述:给定一个字符数组words,和字符串s,返回字符数组中所有字符元素组成的子串在字符串中的位置,要求所有的字符串数组里的元素只在字符串s中存在一次. 算法分析:这道题和strStr很类似.只不 ...