QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197219 | #6378. LaLa and Monster Hunting (Part 1) | Zhou_JK | WA | 1ms | 4356kb | C++23 | 28.6kb | 2023-10-02 13:22:48 | 2023-10-02 13:22:48 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<chrono>
#include<random>
#include<vector>
#include<functional>
#include<iomanip>
#include<algorithm>
using namespace std;
namespace Geometry
{
const double eps=1e-10;
const double PI=acos(-1);
const double INF=1e18;
bool equal(double a,double b)
{
return abs(a-b)<eps;
}
bool less(double a,double b)
{
return b-a>=eps;
}
bool greater(double a,double b)
{
return a-b>=eps;
}
bool less_equal(double a,double b)
{
return less(a,b)||equal(a,b);
}
bool greater_equal(double a,double b)
{
return greater(a,b)||equal(a,b);
}
class Point
{
public:
double x,y;
Point(){x=0,y=0;}
Point(const double &_x,const double &_y):x(_x),y(_y) {}
friend Point operator * (const Point &a,const double &b)
{
return Point(a.x*b,a.y*b);
}
friend Point operator * (const double &a,const Point &b)
{
return Point(a*b.x,a*b.y);
}
friend Point operator / (const Point &a,const double &b)
{
return Point(a.x/b,a.y/b);
}
friend Point operator + (const Point &a,const Point &b)
{
return Point(a.x+b.x,a.y+b.y);
}
Point operator += (const Point &b)
{
x+=b.x,y+=b.y;
return *this;
}
friend Point operator - (const Point &a,const Point &b)
{
return Point(a.x-b.x,a.y-b.y);
}
Point operator -= (const Point &b)
{
x-=b.x,y-=b.y;
return *this;
}
friend double cross(const Point &a,const Point &b)
{
return a.x*b.y-a.y*b.x;
}
friend double dot(const Point &a,const Point &b)
{
return a.x*b.x+a.y*b.y;
}
friend bool operator == (const Point &a,const Point &b)
{
return equal(a.x,b.x)&&equal(a.y,b.y);
}
friend bool operator != (const Point &a,const Point &b)
{
return (!equal(a.x,b.x))||(!equal(a.y,b.y));
}
friend bool operator < (const Point &a,const Point &b)
{
if(equal(a.x,b.x)) return less(a.y,b.y);
else return less(a.x,b.x);
}
friend bool operator > (const Point &a,const Point &b)
{
if(equal(a.x,b.x)) return greater(a.y,b.y);
else return greater(a.x,b.x);
}
friend bool operator <= (const Point &a,const Point &b)
{
if(equal(a.x,b.x)) return less_equal(a.y,b.y);
else return less_equal(a.x,b.x);
}
friend bool operator >= (const Point &a,const Point &b)
{
if(equal(a.x,b.x)) return greater_equal(a.y,b.y);
else return greater_equal(a.x,b.x);
}
Point operator - ()const
{
return Point(-x,-y);
}
double length()const
{
return sqrt(x*x+y*y);
}
Point unit()const
{
return *this/length();
}
double angle()const
{
return atan2(y,x);
}
int quadrant()const
{
if(x>0&&y>=0) return 1;
else if(x<=0&&y>0) return 2;
else if(x<0&&y<=0) return 3;
else if(x>=0&&y<0) return 4;
else return 0;
}
friend double angle(const Point &a,const Point &b)
{
return atan2(cross(a,b),dot(a,b));
}
Point rotate(const double &theta)const
{
return Point(x*cos(theta)-y*sin(theta),x*sin(theta)+y*cos(theta));
}
friend istream &operator>>(istream &in,Point &obj)
{
in>>obj.x>>obj.y;
return in;
}
friend ostream &operator<<(ostream &out,const Point &obj)
{
out<<obj.x<<" "<<obj.y;
return out;
}
};
double distance(const Point &a,const Point &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
enum Direction
{
COUNTER_CLOCKWISE,
CLOCKWISE,
ONLINE_BACK,
ONLINE_FRONT,
ON_SEGMENT
};
istream& operator>>(istream& in,Direction& direction)
{
string value;
in>>value;
if(value=="COUNTER_CLOCKWISE") direction=COUNTER_CLOCKWISE;
else if(value=="CLOCKWISE") direction=CLOCKWISE;
else if(value=="ONLINE_BACK") direction=ONLINE_BACK;
else if(value=="ONLINE_FRONT") direction=ONLINE_FRONT;
else if(value=="ON_SEGMENT") direction=ON_SEGMENT;
else in.setstate(ios::failbit);
return in;
}
ostream& operator<<(ostream& out,const Direction& direction)
{
if(direction==COUNTER_CLOCKWISE) out<<"COUNTER_CLOCKWISE";
else if(direction==CLOCKWISE) out<<"CLOCKWISE";
else if(direction==ONLINE_BACK) out<<"ONLINE_BACK";
else if(direction==ONLINE_FRONT) out<<"ONLINE_FRONT";
else if(direction==ON_SEGMENT) out<<"ON_SEGMENT";
return out;
}
class Line
{
public:
Point a,b;
Line(){}
Line(const Point &_a,const Point &_b):a(_a),b(_b){}
Point projection(const Point &p)const
{
return a+(b-a).unit()*(dot(p-a,b-a)/(b-a).length());
}
Point reflection(const Point &p)const
{
return projection(p)*2-p;
}
Direction direction(const Point &p)const
{
double t=cross(b-a,p-a);
if(greater(t,0)) return COUNTER_CLOCKWISE;
if(less(t,0)) return CLOCKWISE;
double l1=dot(p-a,b-a);
if(less(l1,0)) return ONLINE_BACK;
double l2=dot(b-a,b-a);
if(l1>l2) return ONLINE_FRONT;
else return ON_SEGMENT;
}
double distance(const Point &p)const
{
Point u=projection(p);
if(direction(u)==ON_SEGMENT) return Geometry::distance(u,p);
else return min(Geometry::distance(a,p),Geometry::distance(b,p));
}
friend istream &operator>>(istream &in,Line &obj)
{
in>>obj.a>>obj.b;
return in;
}
friend ostream &operator<<(ostream &out,const Line &obj)
{
out<<obj.a<<" "<<obj.b;
return out;
}
};
bool parallel(const Line &x,const Line &y)
{
return equal(cross(x.b-x.a,y.b-y.a),0);
}
bool orthogonal(const Line &x,const Line &y)
{
return equal(dot(x.b-x.a,y.b-y.a),0);
}
vector<Point> cross_point(const Line &x,const Line &y)
{
if(parallel(x,y)) return {};
Point u=x.a-y.a,v=x.b-x.a,w=y.b-y.a;
double t=cross(w,u)/cross(v,w);
return {x.a+t*v};
}
int sign(double x)
{
return greater(x,0)-less(x,0);
}
bool intersection(const Line &x,const Line &y)
{
if(x.direction(y.a)==ON_SEGMENT||x.direction(y.b)==ON_SEGMENT||y.direction(x.a)==ON_SEGMENT||y.direction(x.b)==ON_SEGMENT) return true;
return sign(cross(x.b-x.a,y.a-x.a))*sign(cross(x.b-x.a,y.b-x.a))<0&&sign(cross(y.b-y.a,x.a-y.a))*sign(cross(y.b-y.a,x.b-y.a))<0;
}
double distance(const Line &x,const Line &y)
{
if(intersection(x,y)) return 0;
else return min({x.distance(y.a),x.distance(y.b),y.distance(x.a),y.distance(x.b)});
}
const int IN=2,ON=1,OUT=0;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
class Polygon
{
private:
vector<Point>g;
public:
Polygon(){}
Polygon(const int &n){g.resize(n);}
Polygon(const vector<Point> &f):g(f){}
void clear()
{
g.clear();
}
void resize(int n)
{
g.resize(n);
}
void push_back(const Point &x)
{
return g.push_back(x);
}
void push_back(const vector<Point> &x)
{
for(const Point &p:x)
g.push_back(p);
return;
}
void pop_back()
{
return g.pop_back();
}
Point& front()
{
return g.front();
}
const Point& front()const
{
return g.front();
}
Point& back()
{
return g.back();
}
const Point& back()const
{
return g.back();
}
size_t size()const
{
return g.size();
}
Point& operator [](const int &i)
{
return g[i];
}
const Point& operator [](const int &i)const
{
return g[i];
}
vector<Point>::iterator begin()
{
return g.begin();
}
vector<Point>::iterator end()
{
return g.end();
}
vector<Point>::const_iterator begin()const
{
return g.begin();
}
vector<Point>::const_iterator end()const
{
return g.end();
}
vector<Point>::reverse_iterator rbegin()
{
return g.rbegin();
}
vector<Point>::reverse_iterator rend()
{
return g.rend();
}
vector<Point>::const_reverse_iterator rbegin()const
{
return g.rbegin();
}
vector<Point>::const_reverse_iterator rend()const
{
return g.rend();
}
double area()const
{
int n=g.size();
double res=0;
for(int i=0;i<n;i++)
res+=cross(g[i],g[(i+1)%n]);
res/=2;
return abs(res);
}
double perimeter()const
{
int n=g.size();
double sum=0;
for(int i=0;i<n;i++)
sum+=distance(g[i],g[(i+1)%n]);
return sum;
}
bool is_convex()const
{
int n=g.size();
for(int i=0;i<n;i++)
if(less(cross(g[(i+1)%n]-g[i],g[(i-1+n)%n]-g[i]),0)) return false;
return true;
}
int point_containment(const Point &a)const
{
int n=g.size();
for(int i=0;i<n;i++)
if(Line(g[i],g[(i+1)%n]).direction(a)==ON_SEGMENT) return ON;
function<bool(const Line &)> check=[=](const Line &l)
{
for(int i=0;i<n;i++)
if(parallel(l,Line(g[i],g[(i+1)%n]))) return false;
for(int i=0;i<n;i++)
if(l.direction(g[i])==ON_SEGMENT||l.direction(g[i])==ONLINE_FRONT||l.direction(g[i])==ONLINE_BACK) return false;
return true;
};
Line l=Line(a,Point(rnd(),rnd()));
while(!check(l))
l=Line(a,Point(rnd(),rnd()));
int s=0;
for(int i=0;i<n;i++)
if(intersection(l,Line(g[i],g[(i+1)%n]))) s++;
if(s&1) return IN;
else return OUT;
}
double convex_diamater()const
{
int n=g.size();
double ans=0;
for(int i=0,j=0;i<n;i++)
{
while(less(cross(g[i]-g[j],g[(i+1)%n]-g[j]),cross(g[i]-g[(j+1)%n],g[(i+1)%n]-g[(j+1)%n]))) j=(j+1)%n;
ans=max(ans,max(distance(g[j],g[i]),distance(g[j],g[(i+1)%n])));
}
return ans;
}
pair<Polygon,Polygon> convex_cut(const Line &l)const
{
Polygon res1,res2;
int n=g.size();
for(int i=0;i<(int)g.size();i++)
{
Point u=g[i],v=g[(i+1)%n];
if(greater_equal(cross(l.b-l.a,u-l.a),0))
{
res1.push_back(u);
if(less(cross(l.b-l.a,v-l.a),0)) res1.push_back(cross_point(Line(u,v),l));
}
else if(greater(cross(l.b-l.a,v-l.a),0)) res1.push_back(cross_point(Line(u,v),l));
}
for(int i=0;i<(int)g.size();i++)
{
Point u=g[i],v=g[(i+1)%n];
if(greater_equal(cross(l.a-l.b,u-l.b),0))
{
res2.push_back(u);
if(less(cross(l.a-l.b,v-l.b),0)) res2.push_back(cross_point(Line(u,v),l));
}
else if(greater(cross(l.a-l.b,v-l.b),0)) res2.push_back(cross_point(Line(u,v),l));
}
return make_pair(res1,res2);
}
Polygon kernel()const;
};
Polygon convex_hull(const vector<Point> &_p)
{
vector<Point> p=_p;
int n=p.size();
if(n<=2)
{
sort(p.begin(),p.end(),[](const Point &a,const Point &b){return a.y==b.y?a.x<b.x:a.y<b.y;});
Polygon res;
for(const Point &q:p)
res.push_back(q);
return res;
}
sort(p.begin(),p.end(),[](const Point &a,const Point &b){return a.x==b.x?a.y<b.y:a.x<b.x;});
vector<int>stk;
int top=0;
for(int i=0;i<n;i++)
{
while(top>=2&&less_equal(cross(p[stk[top-1]]-p[stk[top-2]],p[i]-p[stk[top-1]]),0)) stk.pop_back(),top--;
stk.emplace_back(i),top++;
}
int tmp=top;
for(int i=n-2;i>=0;i--)
{
while(top>tmp&&less_equal(cross(p[stk[top-1]]-p[stk[top-2]],p[i]-p[stk[top-1]]),0)) stk.pop_back(),top--;
stk.emplace_back(i),top++;
}
stk.pop_back(),top--;
vector<Point>hull;
for(int i=0;i<top;i++)
hull.emplace_back(p[stk[i]]);
int t=min_element(hull.begin(),hull.end(),[](const Point &a,const Point &b){return a.y==b.y?a.x<b.x:a.y<b.y;})-hull.begin();
Polygon res;
for(int i=t;i<top;i++)
res.push_back(hull[i]);
for(int i=0;i<t;i++)
res.push_back(hull[i]);
return res;
}
Polygon non_strictly_convex_hull(const vector<Point> &_p)
{
vector<Point> p=_p;
int n=p.size();
if(n<=2)
{
sort(p.begin(),p.end(),[](const Point &a,const Point &b){return a.y==b.y?a.x<b.x:a.y<b.y;});
Polygon res;
for(const Point &q:p)
res.push_back(q);
return res;
}
sort(p.begin(),p.end(),[](const Point &a,const Point &b){return a.x==b.x?a.y<b.y:a.x<b.x;});
vector<int>stk;
int top=0;
for(int i=0;i<n;i++)
{
while(top>=2&&less(cross(p[stk[top-1]]-p[stk[top-2]],p[i]-p[stk[top-1]]),0)) stk.pop_back(),top--;
stk.emplace_back(i),top++;
}
int tmp=top;
for(int i=n-2;i>=0;i--)
{
while(top>tmp&&less(cross(p[stk[top-1]]-p[stk[top-2]],p[i]-p[stk[top-1]]),0)) stk.pop_back(),top--;
stk.emplace_back(i),top++;
}
stk.pop_back(),top--;
vector<Point>hull;
for(int i=0;i<top;i++)
hull.emplace_back(p[stk[i]]);
int t=min_element(hull.begin(),hull.end(),[](const Point &a,const Point &b){return a.y==b.y?a.x<b.x:a.y<b.y;})-hull.begin();
Polygon res;
for(int i=t;i<top;i++)
res.push_back(hull[i]);
for(int i=0;i<t;i++)
res.push_back(hull[i]);
return res;
}
Polygon minkowski_sum(const vector<Point> &a,const vector<Point> &b)
{
assert(a.size()!=0&&b.size()!=0);
Polygon ca=convex_hull(a),cb=convex_hull(b);
int na=ca.size(),nb=cb.size();
vector<Point>la,lb;
for(int i=0;i<na;i++)
la.emplace_back(ca[(i+1)%na]-ca[i]);
for(int i=0;i<nb;i++)
lb.emplace_back(cb[(i+1)%nb]-cb[i]);
int pa=0,pb=0;
vector<Point> l;
l.emplace_back(ca[0]+cb[0]);
while(pa<(int)la.size()&&pb<(int)lb.size())
{
double val=cross(la[pa],lb[pb]);
if(greater(val,0)) l.emplace_back(l.back()+la[pa]),pa++;
else if(less(val,0)) l.emplace_back(l.back()+lb[pb]),pb++;
else l.emplace_back(l.back()+la[pa]+lb[pb]),pa++,pb++;
}
while(pa<(int)la.size())
l.emplace_back(l.back()+la[pa]),pa++;
while(pb<(int)lb.size())
l.emplace_back(l.back()+lb[pb]),pb++;
Polygon res=convex_hull(l);
return res;
}
Polygon half_plane_intersection(const vector<Line> &l,double x1=-INF,double y1=-INF,double x2=INF,double y2=INF)
{
vector<pair<double,Line>>f;
for(int i=0;i<(int)l.size();i++)
f.emplace_back((l[i].b-l[i].a).angle(),l[i]);
f.emplace_back(0,Line(Point(x1,y1),Point(x2,y1)));
f.emplace_back(PI/2,Line(Point(x2,y1),Point(x2,y2)));
f.emplace_back(PI,Line(Point(x2,y2),Point(x1,y2)));
f.emplace_back(-PI/2,Line(Point(x1,y2),Point(x1,y1)));
int n=f.size();
sort(f.begin(),f.end(),[](const pair<double,Line> &a,const pair<double,Line> &b){return !equal(a.first,b.first)?a.first<b.first:a.second.direction(b.second.a)==CLOCKWISE;});
vector<Line>Ql(n);
vector<Point>Qp(n);
Polygon res;
int head=0,tail=-1;
Ql[++tail]=f[0].second;
for(int i=1;i<n;i++)
if(!equal(f[i].first,f[i-1].first))
{
while(head<tail&&f[i].second.direction(Qp[tail-1])==CLOCKWISE) tail--;
while(head<tail&&f[i].second.direction(Qp[head])==CLOCKWISE) head++;
Ql[++tail]=f[i].second;
if(head<tail)
{
vector<Point> tmp=cross_point(Ql[tail],Ql[tail-1]);
if(!tmp.empty()) Qp[tail-1]=tmp[0];
else return res;
}
}
while(head<tail&&Ql[head].direction(Qp[tail-1])==CLOCKWISE) tail--;
while(head<tail&&Ql[tail].direction(Qp[head])==CLOCKWISE) head++;
vector<Point> tmp=cross_point(Ql[tail],Ql[head]);
if(tmp.empty()||tail-head+1<=2) return res;
for(int i=head;i<tail;i++)
res.push_back(Qp[i]);
res.push_back(tmp[0]);
return res;
}
Polygon Polygon::kernel()const
{
int n=g.size();
vector<Line>l;
for(int i=0;i<n;i++)
l.emplace_back(Line(g[i],g[(i+1)%n]));
return half_plane_intersection(l);
}
double closest_pair(const vector<Point> &_p)
{
vector<Point>p=_p;
sort(p.begin(),p.end(),[](const Point &a,const Point &b){return a.x<b.x;});
function<double(const int &,const int &)> solve=[&](const int &l,const int &r)
{
if(r-l+1<=1) return INF;
if(r-l+1<=7)
{
double ans=INF;
sort(p.begin()+l,p.begin()+r+1,[](const Point &a,const Point &b){return a.y<b.y;});
for(int i=l;i<=r;i++)
for(int j=i+1;j<=r;j++)
ans=min(ans,distance(p[i],p[j]));
return ans;
}
int mid=(l+r)/2;
double w=p[mid].x;
double d=min(solve(l,mid),solve(mid+1,r));
inplace_merge(p.begin()+l,p.begin()+mid+1,p.begin()+r+1,[](const Point &a,const Point &b){return a.y<b.y;});
vector<Point>q;
for(int i=l;i<=r;i++)
if(abs(w-p[i].x)<=d) q.emplace_back(p[i]);
for(int i=0,j=0;i<(int)q.size();i++)
{
while(j<(int)q.size()&&q[j].y<=q[i].y+d) j++;
for(int k=i+1;k<j;k++)
d=min(d,distance(q[i],q[k]));
}
return d;
};
return solve(0,p.size()-1);
}
class Circle
{
public:
Point o;
double r;
Circle(){}
Circle(const Point &_o,const double &_r):o(_o),r(_r){}
friend istream &operator>>(istream &in,Circle &obj)
{
in>>obj.o>>obj.r;
return in;
}
friend ostream &operator<<(ostream &out,const Circle &obj)
{
out<<obj.o<<" "<<obj.r;
return out;
}
double area()const
{
return PI*r*r;
}
bool tangent(const Line &l)const
{
return equal(Geometry::distance(l.projection(o),o),r);
}
int point_containment(const Point &p)const
{
double d=distance(o,p);
if(equal(d,r)) return ON;
else if(less(d,r)) return IN;
else return OUT;
}
vector<Point>cross_point(const Line &l)const
{
Point pr=l.projection(o),e=(l.b-l.a).unit();
double d=distance(pr,o);
if(greater(d,r)) return {};
double t=sqrt(r*r-distance(pr,o)*distance(pr,o));
if(equal(t,0)) return {pr};
else return {pr-e*t,pr+e*t};
}
vector<Point>cross_point(const Circle &c)const
{
double d=distance(o,c.o);
if(less(d,abs(r-c.r))||greater(d,r+c.r)) return {};
double x=(r*r-c.r*c.r+d*d)/(d*2),h=sqrt(r*r-x*x);
Point p=o+(c.o-o).unit()*x;
if(equal(d,abs(r-c.r))||equal(d,r+c.r)) return {p};
Point v=(c.o-o).unit().rotate(PI/2)*h;
return {p-v,p+v};
}
vector<Point>tangent(const Point &p)const
{
double d=distance(o,p);
if(greater(r,d)) return {};
if(equal(d,r)) return {p};
return cross_point(Circle(p,sqrt(d*d-r*r)));
}
vector<Line>common_tangent(const Circle &c)const
{
vector<Line>f=common_tangent_out(c),g=common_tangent_in(c);
for(const Line &l:g)
f.emplace_back(l);
g.clear();
sort(f.begin(),f.end(),[](const Line &x,const Line &y){return x.a.x<y.a.x||(x.a.x==y.a.x&&x.a.y<y.a.y);});
return f;
}
double intersection_area(const Point &a,const Point &b)const
{
bool ta=less_equal(distance(o,a),r),tb=less_equal(distance(o,b),r);
if(ta&&tb) return cross(a-o,b-o)/2;
vector<Point>t=cross_point(Line(b,a));
if(ta&&!tb) return angle(t.front()-o,b-o)*r*r/2+cross(a-o,t.front()-o)/2;
if(!ta&&tb) return angle(a-o,t.back()-o)*r*r/2+cross(t.back()-o,b-o)/2;
double s=angle(a-o,b-o)*r*r/2;
if(greater_equal(Line(a,b).distance(o),r)) return s;
return s+angle(t.front()-o,t.back()-o)*r*r/2-cross(t.front()-o,t.back()-o)/2;
}
double intersection_area(const Polygon &g)const
{
int n=g.size();
double s=0;
for(int i=0;i<n;i++)
s+=intersection_area(g[i],g[(i+1)%n]);
return s;
}
double intersection_area(const Circle &c)const
{
double d=distance(o,c.o);
if(greater(d,r+c.r)) return 0;
if(less_equal(d,abs(r-c.r))) return min(area(),c.area());
vector<Point>t=cross_point(c);
double alpha=acos((d*d+r*r-c.r*c.r)/(2*d*r))*2,beta=acos((d*d+c.r*c.r-r*r)/(2*d*c.r))*2;
double s1=alpha*r*r/2,s2=beta*c.r*c.r/2,s3=sin(alpha)*r*r/2+sin(beta)*c.r*c.r/2;
return s1+s2-s3;
}
vector<Line>common_tangent_out(const Circle &c)const
{
if(equal(r,c.r))
{
Point p=(c.o-o).unit().rotate(PI/2)*r;
return {Line(o-p,c.o-p),Line(o+p,c.o+p)};
}
double d=distance(o,c.o);
if(less(d,abs(r-c.r))) return {};
Point p((o.x*c.r-c.o.x*r)/(c.r-r),(o.y*c.r-c.o.y*r)/(c.r-r));
vector<Point>p1=tangent(p),p2=c.tangent(p);
vector<Line>res;
for(const Point &u:p1)
for(const Point &v:p2)
if(u!=v&&tangent(Line(u,v))) res.emplace_back(Line(u,v));
return res;
}
vector<Line>common_tangent_in(const Circle &c)const
{
double d=distance(o,c.o);
if(less_equal(d,abs(r-c.r))) return {};
Point p((o.x*c.r+c.o.x*r)/(r+c.r),(o.y*c.r+c.o.y*r)/(r+c.r));
vector<Point>p1=tangent(p),p2=c.tangent(p);
vector<Line>res;
for(const Point &u:p1)
for(const Point &v:p2)
if(u!=v&&tangent(Line(u,v))) res.emplace_back(Line(u,v));
return res;
}
};
const int SEPARATED=4,CIRCUMSCRIBED=3,INTERSECTED=2,INSCRIBED=1,INCLUDED=0;
int intersection(const Circle &a,const Circle &b)
{
double d=distance(a.o,b.o);
if(greater(d,a.r+b.r)) return SEPARATED;
else if(equal(d,a.r+b.r)) return CIRCUMSCRIBED;
else if(greater(d,abs(a.r-b.r))) return INTERSECTED;
else if(equal(d,abs(a.r-b.r))) return INSCRIBED;
else return INCLUDED;
}
class Triangle
{
public:
Point A,B,C;
Triangle(){}
Triangle(const Point &_A,const Point &_B,const Point &_C):A(_A),B(_B),C(_C){}
friend istream &operator>>(istream &in,Triangle &obj)
{
in>>obj.A>>obj.B>>obj.C;
return in;
}
friend ostream &operator<<(ostream &out,const Triangle &obj)
{
out<<obj.A<<" "<<obj.B<<" "<<obj.C;
return out;
}
Circle inscribed_circle()const
{
double a=distance(B,C),b=distance(A,C),c=distance(A,B);
double p=(a+b+c)/2;
double s=abs(cross(B-A,C-A))/2;
double r=s/p;
Point o((a*A.x+b*B.x+c*C.x)/(a+b+c),(a*A.y+b*B.y+c*C.y)/(a+b+c));
return Circle(o,r);
}
Circle circumscribed_circle()const
{
double t1=A.x*A.x+A.y*A.y;
double t2=B.x*B.x+B.y*B.y;
double t3=C.x*C.x+C.y*C.y;
double t=A.x*B.y+B.x*C.y+C.x*A.y-A.x*C.y-B.x*A.y-C.x*B.y;
Point o((t2*C.y+t1*B.y+t3*A.y-t2*A.y-t3*B.y-t1*C.y)/t/2,(t3*B.x+t2*A.x+t1*C.x-t1*B.x-t2*C.x-t3*A.x)/t/2);
double a=distance(B,C),b=distance(A,C),c=distance(A,B);
double s=abs(cross(B-A,C-A))/2;
double r=a*b*c/(4*s);
return Circle(o,r);
}
};
Circle smallest_enclosing_circle(const vector<Point> &_p)
{
vector<Point>p=_p;
shuffle(p.begin(),p.end(),rnd);
int n=p.size();
Circle c=Circle(Point(0,0),0);
for(int i=0;i<n;i++)
if(c.point_containment(p[i])==OUT)
{
c=Circle(p[i],0);
for(int j=0;j<i;j++)
if(c.point_containment(p[j])==OUT)
{
c=Circle((p[i]+p[j])/2,distance(p[i],p[j])/2);
for(int k=0;k<j;k++)
if(c.point_containment(p[k])==OUT)
c=Triangle(p[i],p[j],p[k]).circumscribed_circle();
}
}
return c;
}
}
using namespace Geometry;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int n;
cin>>n;
vector<Circle>c(n);
for(int i=0;i<n;i++)
cin>>c[i];
Point q=Point(0,0);
for(int i=0;i<n;i++)
if(c[i].point_containment(q))
{
cout<<"Yes";
return 0;
}
if(n==1)
{
cout<<"No";
return 0;
}
vector<Point>p(n);
for(int i=0;i<n;i++)
p[i]=c[i].o;
Polygon g=convex_hull(p);
if(g.point_containment(q))
{
cout<<"Yes";
return 0;
}
sort(c.begin(),c.end(),[=](const Circle &a,const Circle &b){return a.o.angle()<b.o.angle();});
for(int i=0;i<n;i++)
{
vector<Line>l=c[i].common_tangent_out(c[(i+1)%n]);
if(l.empty()) continue;
Line l1=l[0],l2=l[1];
Polygon gg(6);
gg[0]=c[i].o,gg[1]=l1.a,gg[2]=l1.b,gg[3]=c[(i+1)%n].o,gg[4]=l2.b,gg[5]=l2.a;
if(gg.point_containment(q))
{
cout<<"Yes";
return 0;
}
}
cout<<"No";
return 0;
}
/*
8
0 -8 3
9 -10 7
5 -7 1
4 -7 2
3 -7 5
0 -5 1
3 -7 2
2 -7 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3912kb
input:
3 -3 0 1 0 0 3 3 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
3 2 0 1 0 2 1 -5 -5 3
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 3 3 1
output:
No
result:
ok answer is NO
Test #4:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
1 -3 -2 5
output:
Yes
result:
ok answer is YES
Test #5:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
2 1 3 5 -2 -6 1
output:
Yes
result:
ok answer is YES
Test #6:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
3 -14 7 7 2 -1 3 8 -1 9
output:
Yes
result:
ok answer is YES
Test #7:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
4 5 -3 9 -10 6 5 4 2 2 -8 10 2
output:
Yes
result:
ok answer is YES
Test #8:
score: 0
Accepted
time: 0ms
memory: 3992kb
input:
5 -2 -1 4 9 10 5 -9 2 4 6 -3 5 0 -4 10
output:
Yes
result:
ok answer is YES
Test #9:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
6 -3 -1 6 3 1 8 1 2 4 1 -3 5 3 7 4 5 5 4
output:
Yes
result:
ok answer is YES
Test #10:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
7 3 -2 5 -1 10 7 -1 10 3 1 -5 5 -9 -9 4 -5 -10 5 1 4 9
output:
Yes
result:
ok answer is YES
Test #11:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
8 3 -1 5 1 7 2 -2 -10 6 -1 6 4 -2 0 9 0 9 6 -7 1 7 5 -2 7
output:
Yes
result:
ok answer is YES
Test #12:
score: 0
Accepted
time: 0ms
memory: 4052kb
input:
9 -1 0 8 2 0 8 -8 -10 2 8 -2 1 -5 -8 0 -2 -3 5 -7 -4 9 -3 9 8 -10 10 7
output:
Yes
result:
ok answer is YES
Test #13:
score: 0
Accepted
time: 0ms
memory: 4052kb
input:
10 -3 0 4 3 -1 8 7 0 6 -6 -10 2 4 5 2 -7 -5 0 -7 4 7 10 7 0 -3 0 9 7 -6 6
output:
Yes
result:
ok answer is YES
Test #14:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
11 0 -4 7 5 9 4 -8 0 2 -10 8 5 7 9 1 7 8 8 4 -8 5 8 6 9 2 -7 8 3 4 0 10 -8 10
output:
Yes
result:
ok answer is YES
Test #15:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
12 2 3 5 -5 -9 5 5 -10 3 9 -10 9 -4 -10 0 10 5 1 -3 -5 7 2 10 10 0 7 10 -10 -7 5 -7 1 9 0 4 8
output:
Yes
result:
ok answer is YES
Test #16:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
13 3 0 5 -12 0 4 2 2 8 6 3 4 5 -3 0 3 -4 9 -9 5 9 -1 -3 5 4 -1 2 1 -3 10 -10 2 3 -7 9 7 -6 9 3
output:
Yes
result:
ok answer is YES
Test #17:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
14 2 1 4 8 -3 0 -7 -4 2 10 -6 5 -4 -4 4 1 1 2 4 6 5 -3 -5 5 10 -10 1 4 -6 2 -4 9 3 -3 10 8 -6 6 10 8 -8 1
output:
Yes
result:
ok answer is YES
Test #18:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
15 1 2 6 -1 -2 3 9 -10 2 0 5 6 8 10 8 -2 -6 9 -7 4 0 6 -10 1 -6 -3 10 7 -3 2 5 -9 5 10 0 3 9 -6 1 0 -1 3 -8 -3 5
output:
Yes
result:
ok answer is YES
Test #19:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
16 0 -8 9 1 -4 0 -8 -3 7 -6 -7 7 3 -7 9 -9 7 10 4 1 1 -9 2 7 1 -7 7 -5 -3 3 4 4 3 -1 -9 2 -4 -1 7 -8 -2 10 -6 1 3 -1 -8 3
output:
Yes
result:
ok answer is YES
Test #20:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
17 0 4 7 -6 8 0 6 6 4 3 -8 7 -6 2 6 -10 8 3 -10 9 8 -9 1 9 -10 8 2 -9 0 7 -5 1 1 2 -4 5 -3 -5 0 -4 0 6 1 -2 0 6 -4 4 -2 -7 3
output:
Yes
result:
ok answer is YES
Test #21:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
18 -3 -3 1 5 5 8 7 -6 8 -10 3 4 10 1 2 7 -10 10 3 -4 9 1 5 6 -10 -4 1 3 -4 2 4 -5 9 3 -6 4 3 1 7 9 -3 5 6 9 8 5 -6 2 9 -2 5 10 3 2
output:
Yes
result:
ok answer is YES
Test #22:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
19 4 -1 8 -5 5 1 -5 -4 7 -9 -10 7 -8 6 0 10 10 6 2 -6 9 1 1 6 -9 -6 7 -8 -5 5 2 -7 9 1 -1 4 -7 4 5 -3 3 10 1 6 6 2 4 6 -7 3 10 -5 -4 8 9 -4 6
output:
Yes
result:
ok answer is YES
Test #23:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
20 1 0 2 -10 3 7 9 -3 7 0 -10 7 7 -6 8 -5 6 7 5 6 5 7 8 8 -4 -10 9 -8 -10 8 2 -5 5 -5 -5 9 -5 9 10 1 9 1 -7 6 4 0 -1 6 -5 7 9 -1 -4 5 -4 4 6 3 6 2
output:
Yes
result:
ok answer is YES
Test #24:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
3 -6 -6 2 -10 -8 8 -7 -7 5
output:
No
result:
ok answer is NO
Test #25:
score: 0
Accepted
time: 0ms
memory: 4284kb
input:
4 -7 -9 3 -3 -6 2 9 -1 2 0 -7 3
output:
No
result:
ok answer is NO
Test #26:
score: 0
Accepted
time: 0ms
memory: 4256kb
input:
5 2 -6 3 -2 -8 2 -3 -5 1 -5 -9 1 0 -7 1
output:
No
result:
ok answer is NO
Test #27:
score: 0
Accepted
time: 0ms
memory: 4164kb
input:
6 10 9 6 7 10 3 6 10 8 3 7 3 -4 8 3 7 5 4
output:
No
result:
ok answer is NO
Test #28:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
7 -9 8 6 -8 1 4 -10 -1 1 -7 10 4 -5 9 1 -8 10 6 -10 9 5
output:
No
result:
ok answer is NO
Test #29:
score: 0
Accepted
time: 0ms
memory: 4196kb
input:
8 0 -8 3 9 -10 7 5 -7 1 4 -7 2 3 -7 5 0 -5 1 3 -7 2 2 -7 4
output:
No
result:
ok answer is NO
Test #30:
score: 0
Accepted
time: 0ms
memory: 4320kb
input:
9 -1 -9 3 7 -7 2 10 0 1 -8 -10 2 -5 -10 1 8 -4 2 8 -9 5 8 -5 4 8 -7 3
output:
No
result:
ok answer is NO
Test #31:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
10 -7 -8 1 -7 -9 3 -7 1 1 -7 -1 1 -6 3 2 -10 6 3 -10 -9 2 -6 2 1 -8 -9 3 -5 -3 1
output:
No
result:
ok answer is NO
Test #32:
score: 0
Accepted
time: 0ms
memory: 4224kb
input:
11 -7 -3 4 1 -10 3 -10 -5 5 -7 -7 4 -10 2 1 0 -8 1 -4 -4 2 -10 -3 3 -6 -7 5 -6 -8 3 2 -10 2
output:
No
result:
ok answer is NO
Test #33:
score: 0
Accepted
time: 0ms
memory: 4256kb
input:
12 -8 10 4 -8 8 5 -9 8 3 -9 9 6 1 7 3 -6 8 7 1 9 2 1 7 2 -6 8 3 -7 0 1 -3 6 4 2 10 2
output:
No
result:
ok answer is NO
Test #34:
score: 0
Accepted
time: 0ms
memory: 4316kb
input:
13 -7 -1 1 -6 3 4 -9 8 7 1 9 1 -10 9 7 -5 9 6 -1 10 4 -5 4 4 -8 7 1 0 6 1 -9 0 4 -1 6 1 -8 10 5
output:
No
result:
ok answer is NO
Test #35:
score: 0
Accepted
time: 0ms
memory: 4356kb
input:
14 -8 -6 1 -9 -6 2 -6 3 3 -10 7 7 -7 9 8 -6 6 2 -10 5 9 -7 -1 3 0 8 1 -9 10 9 -10 -10 1 -6 5 4 -10 7 6 -2 8 1
output:
No
result:
ok answer is NO
Test #36:
score: 0
Accepted
time: 0ms
memory: 4324kb
input:
15 9 7 5 9 10 6 9 1 4 9 4 7 10 7 2 10 0 1 9 9 9 9 10 5 8 4 5 9 -2 4 7 -2 3 9 7 3 3 1 1 7 9 1 7 4 5
output:
No
result:
ok answer is NO
Test #37:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
16 -8 10 5 -9 10 2 -10 -2 2 -8 1 2 -5 -5 2 -10 1 6 -6 9 2 -8 4 1 -7 -5 4 -7 5 2 -9 -8 2 -10 -9 2 -8 -8 4 -8 -1 5 -6 -9 2 -7 5 1
output:
No
result:
ok answer is NO
Test #38:
score: 0
Accepted
time: 0ms
memory: 4216kb
input:
17 -8 -8 2 -10 3 5 -3 -7 2 -6 -6 5 -8 0 4 -2 -10 3 -9 -9 1 -9 -5 2 -9 4 3 -8 -3 2 -7 -6 1 -8 3 3 -5 -8 2 -6 -2 1 -6 1 2 -10 5 3 -5 -2 1
output:
No
result:
ok answer is NO
Test #39:
score: 0
Accepted
time: 0ms
memory: 4212kb
input:
18 4 -2 1 7 -10 1 9 -6 2 7 9 5 9 8 6 9 2 4 10 3 4 7 9 7 8 7 5 6 1 1 4 -2 1 9 0 4 7 10 7 5 3 3 2 7 2 4 6 3 10 -5 5 8 0 4
output:
No
result:
ok answer is NO
Test #40:
score: 0
Accepted
time: 0ms
memory: 4216kb
input:
19 -2 10 4 10 9 2 -4 7 3 1 8 4 -7 2 2 -10 3 2 5 6 1 -3 10 6 -7 7 5 -2 10 8 -10 8 4 -3 5 3 -3 9 2 4 8 4 7 8 3 -8 4 1 4 10 1 9 7 1 -2 6 2
output:
No
result:
ok answer is NO
Test #41:
score: 0
Accepted
time: 0ms
memory: 4320kb
input:
20 9 7 4 9 6 1 -9 8 2 1 9 6 3 8 3 1 7 2 4 6 2 2 9 7 -5 7 1 9 3 2 -1 9 4 5 5 3 -10 9 3 1 9 1 -7 8 1 7 9 3 10 10 9 5 8 3 1 5 1 -7 10 1
output:
No
result:
ok answer is NO
Test #42:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
490 -401120 517405 392832 80224 -103481 797533 754989 -41760 559341 416563 -695192 201277 -141668 -665827 898034 -236708 -535297 871413 993788 606278 381486 589063 -611773 228296 -919383 718355 908770 -657978 42950 738469 -304514 -146524 532007 433672 -184231 820655 -142774 -3858 384901 -879148 1653...
output:
Yes
result:
ok answer is YES
Test #43:
score: 0
Accepted
time: 1ms
memory: 4060kb
input:
491 -872659 -699808 892915 872659 699808 991810 659525 -631701 442804 -305260 788091 674223 -246189 -657824 701213 -486340 702251 412375 943552 -220491 91527 835536 759608 489761 -165917 716863 320734 -544207 -167639 633696 863791 16438 917784 797655 370791 426650 -455839 649078 942747 -440922 -7269...
output:
Yes
result:
ok answer is YES
Test #44:
score: 0
Accepted
time: 1ms
memory: 3988kb
input:
492 85070 -163392 274400 -425350 816960 79480 830750 922585 987668 894794 -69053 51789 746578 846338 169004 725416 -943389 613749 157359 442389 642057 856229 539565 355115 -98088 -94634 464783 -7867 -406308 801658 -133127 -884007 341601 645211 455900 647745 283048 445596 350027 828628 -554092 314351...
output:
Yes
result:
ok answer is YES
Test #45:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
493 -337499 -223669 204963 337499 223669 175181 -62568 -997282 924216 -785855 -790106 508347 -504113 926160 207804 -811011 143840 746657 299819 -274530 253669 81562 70497 364775 -992771 -63630 158939 240722 -191363 990373 68483 -299216 580892 125440 -878042 60112 564463 -493982 902303 -582047 -50698...
output:
Yes
result:
ok answer is YES
Test #46:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
494 278560 196119 494170 -835680 -588357 732997 613605 -784073 726646 896480 648928 377870 630656 -778834 785049 95978 -274271 323791 952706 -309202 822553 -118178 -765503 915366 -409835 470311 188171 244173 723222 486152 585735 349683 511310 794978 708028 551980 283009 -544485 17144 -489404 -55428 ...
output:
Yes
result:
ok answer is YES
Test #47:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
495 166424 -9538 213430 -918208 12496 312838 -553881 -141147 169771 -862671 180067 594468 -869538 -459958 791131 203963 -46925 673657 792949 905244 132725 -244283 36408 283748 -702543 -547763 551168 307437 137180 567371 -825875 -653582 267833 -631352 770632 418429 -16415 -658120 746828 -64666 -58802...
output:
Yes
result:
ok answer is YES
Test #48:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
496 141268 -980616 572051 -35317 245154 169086 -347003 -269510 425841 301475 9661 617109 50389 520735 575503 -379867 -355207 88273 914615 550032 194184 341380 -90691 58960 -881531 926153 941231 -935000 418250 384889 -66455 76375 149388 262359 -608680 244962 -648253 -456285 187461 -424908 948435 4146...
output:
Yes
result:
ok answer is YES
Test #49:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
497 -485048 834780 656812 242524 -417390 975403 87235 564073 339746 -440124 -4377 554520 556890 252197 524586 -97029 -336887 637628 -693086 -572966 537693 -937215 -295332 818169 661581 -542414 928902 -702501 -476007 661734 -501428 -974254 595982 788266 -154126 996801 262451 -70362 269240 -64749 3040...
output:
Yes
result:
ok answer is YES
Test #50:
score: 0
Accepted
time: 1ms
memory: 4000kb
input:
498 63374 167580 194225 -226071 -758060 212291 -243179 401960 871253 632017 -974472 774851 -775638 434525 257145 523264 -540226 852177 -118921 -609603 361540 536935 -960950 998211 -779714 820637 150783 -130275 -464805 348441 929369 -957670 242705 147736 880691 143486 993451 -101779 114756 161981 -22...
output:
Yes
result:
ok answer is YES
Test #51:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
499 85385 -63451 71318 -170770 126902 563893 256536 487293 697550 -13786 580255 476072 -736160 21495 342847 -512540 -596790 20229 414967 -752637 33406 -241751 818909 36982 -189497 831393 760606 -760839 -52270 815865 -426433 476785 751461 811316 -805777 619598 -175099 -59090 281702 342361 -219269 999...
output:
Yes
result:
ok answer is YES
Test #52:
score: 0
Accepted
time: 1ms
memory: 3940kb
input:
500 -546618 156961 709962 900993 -979479 482300 -278234 745342 850180 -575239 -972802 40718 -311366 -205433 176044 -533631 703878 841930 148899 -585743 772676 485273 813709 392242 -879325 -635405 21200 487413 810421 69597 634966 771073 85875 905717 711266 931353 -510826 -168951 658710 -942024 -46634...
output:
Yes
result:
ok answer is YES
Test #53:
score: -100
Wrong Answer
time: 1ms
memory: 4356kb
input:
501 719919 -109933 580601 662951 -723491 144244 574654 470175 668547 46421 729922 163745 700192 654929 755179 782717 378301 328766 862814 706616 346048 667904 -111318 156500 579368 137888 389074 -223390 923203 162053 584358 162237 505492 709352 -567378 114068 955894 570460 182478 231455 479087 29651...
output:
Yes
result:
wrong answer expected NO, found YES