URAL 1062 - Triathlon(半平面交)
这个题乍眼一看好像很简单,然后我就认为u、v、w只要有全部比另外一个人小的就不能win,否则就能win,但是这个思路只对了一半
不能win的结论是正确的,但是win的结论不止排除这一个条件
将这个人与其他人的条件列式
如果都win的话,则满足 x/v+y/u+(k-x-y)/w(i的)<x/v+y/u+(k-x-y)/w(j的)由此构成n条直线(半平面),然后求交,如果有交集,则输出Yes,否则No
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double eps = 1e-8; struct Point
{
double x,y;
Point(double x=0,double y=0):x(x),y(y) {}
}; typedef Point Vector; Vector operator - (Point A, Point B)
{
return Vector(A.x-B.x, A.y-B.y);
}
struct Line
{
Point p;
Vector v;
double ang;
Line() {}
Line(Point p,Vector v):p(p),v(v)
{
ang=atan2(v.y,v.x);
}
bool operator < (const Line& L) const
{
return ang<L.ang;
}
}; double Cross(Vector A, Vector B)
{
return A.x*B.y - A.y*B.x;
} bool Onleft(Line L, Point p)
{
return Cross(L.v, p-L.p)>0;
} Point GetIntersection(Line a, Line b)
{
Vector u = a.p-b.p;
double t = Cross(b.v, u)/Cross(a.v, b.v);
return Point(a.p.x+a.v.x*t, a.p.y+a.v.y*t);
} int BPMJ(Line *L, int n, Point *poly)
{
sort(L,L+n);
int first,last;
Point *p = new Point[n];
Line *q = new Line[n];
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] = GetIntersection(q[last-1], q[last]);
}
while(first<last && !Onleft(q[first], p[last-1])) last--;
if(last-first<=1)return 0;
p[last] = GetIntersection(q[last], q[first]);
int m = 0;
for(int i=first; i<=last; i++)
poly[m++] = p[i];
return m;
} double k=10000.0;
int u[110],v[110],w[110];
Point poly[110];
Line L[110]; int main()
{
int n;
while(scanf("%d",&n)==1)
{
for(int i=0; i<n; i++)
{
scanf("%d%d%d",&u[i],&v[i],&w[i]);
}
for(int i=0; i<n; i++)
{
int f=0;
for(int j=0; j<n; j++)
{
if(j!=i && u[i]<=u[j] && v[i]<=v[j] && w[i]<=w[j])
{
f=1;
break;
}
}
if(f==1)
printf("No\n");
else
{
Point p;
int ct=0;
for(int j=0; j<n; j++)
{
if(j!=i && u[i]>=u[j] && v[i]>=v[j] && w[i]>=w[j])
continue;
else if(j!=i)
{
double A=k/v[j]-k/v[i]-k/w[j]+k/w[i];
double B=k/u[j]-k/u[i]-k/w[j]+k/w[i];
double C=k/w[j]-k/w[i];
if(fabs(A)>fabs(B))
p=Point(-C/A,0);
else
p=Point(0,-C/B);
Vector v(B,-A);
L[ct++] = Line(p,v);
}
}
L[ct++] = Line(Point(0,0), Vector(0,-1));
L[ct++] = Line(Point(0,0), Vector(1,0));
L[ct++] = Line(Point(0,1), Vector(-1,1));
if(BPMJ(L,ct,poly))printf("Yes\n");
else printf("No\n");
}
}
}
return 0;
}
URAL 1062 - Triathlon(半平面交)的更多相关文章
- POJ 1755 Triathlon [半平面交 线性规划]
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6912 Accepted: 1790 Descrip ...
- LA 2218 Triathlon(半平面交)
Triathlon [题目链接]Triathlon [题目类型]半平面交 &题解: 做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空. 还有刘汝佳的代码总是写const +& ...
- LA2218 Triathlon /// 半平面交 oj22648
题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...
- 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] ...
随机推荐
- [BZOJ 3489] A simple rmq problem 【可持久化树套树】
题目链接:BZOJ - 3489 题目分析 “因为是OJ上的题,就简单点好了.”——出题人 真的..好..简单... 首先,我们求出每个数的前一个与它相同的数的位置,即 prev[i] ,如果前面没有 ...
- ios7新特性2--多任务提升
iOS 7 为应用程序提供新的后台执行模式: 应用程序需要需要下载新内容,可以向系统注册,这样程序会被定期唤起或者启动,然后可以在后台下载内容.要注册这个功能,需要打开Info.plist 文件,设置 ...
- 【技术贴】解决myeclipse SVN 提交代码 commit:remains in tree-c
[技术贴]解决myeclipse SVN 提交代码 commit:remains in tree-conflict错误的解决办法 错误是:Aborting commit: xxxxx' remains ...
- 【HDOJ】4902 Nice boat
区间线段树.题目还不错. /* */ #include <iostream> #include <string> #include <map> #include & ...
- 悟透Javascript之 原型prototype
构造函数的Prototype上定义的方法确实可以通过对象直接调用,而且代码是共享的.我表示我不懂.太难理解了,艹.在Javascript中,prototype不但能让对象共享自己的财富,而且proto ...
- 265行JavaScript代码的第一人称3D H5游戏Demo【个人总结1】
本文目的是分解前面的代码.其实,它得逻辑很清楚,只是对于我这种只是用过 Canvas 画线(用过 Fabric.js Canvas库)的人来说,这个还是很复杂的.我研究这个背景天空也是搞了一天,下面就 ...
- HDOJ 1995 汉诺塔V
Problem Description 用1,2,-,n表示n个盘子,称为1号盘,2号盘,-.号数大盘子就大.经典的汉诺塔问 题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔 ...
- 2013=7=29 nyist 13题
Fibonacci数 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 无穷数列1,1,2,3,5,8,13,21,34,55...称为Fibonacci数列,它可以递归地 ...
- Java 内存泄露的理解与解决过程
本文详细地介绍了Java内存管理的原理,以及内存泄露产生的原因,同时提供了一些列解决Java内存泄露的方案,希望对各位Java开发者有所帮助. Java内存管理机制 在C++ 语言中,如果需要动态分配 ...
- poj 1847 Tram【spfa最短路】
Tram Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12005 Accepted: 4365 Description ...