LA2218 Triathlon
2024-10-19 19:30:04
题意
分析
设出长度\(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;
}
最新文章
- android Broadcast介绍
- css text-overflow:ellipsis 文字多余剪切
- Java简单示例-用户登录、单个页面的增删改查及简单分页
- [HTML5]HTML结构性元素(Structure)
- Atom 和 markdown 基本使用
- RabbitMQ 安装
- 微软BI 之SSIS 系列 - 再谈Lookup 缓存
- [ActionScript 3.0] AS3动画类Tweener中滤镜的运用
- Python操作excel(xlrd和xlwt)
- jQuery提交form表单
- css中盒子宽高的auto
- thinkphp CURD 1
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- ThreadPool study
- Standalone的更改方式
- Intellij IDEA编辑golang时无法加载系统GOPATH变量
- join和子查询的一点点思考
- 最长公共子序列lcs 51nod1006
- BZOJ3191或洛谷2059 [JLOI2013]卡牌游戏
- .NET中使用Redis:http://www.cnblogs.com/yangecnu/p/Introduct-Redis-in-DotNET.html