QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648651#7800. Every Queenqinglu09WA 53ms4008kbC++148.0kb2024-10-17 19:49:062024-10-17 19:49:10

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 19:49:10]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:4008kb
  • [2024-10-17 19:49:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
#define lowbit(x) (x&-x)
#define gcd __gcd
#define i128 __int128
#define rep(i, a, b) for(ll i = (a); i <= (b); i++)
#define per(i, a, b) for(ll i = (a); i >= (b); i--)
const int N=1e6+10,M=1e3+10;
const ll mod=1e9+7;
const ld eps=1e-12;
const double pi=acos(-1.0);
const double pi1=pi/180,pi2=180/pi;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//unordered_map<int,int>mp;
#define poly vector<int>

#define double ld

double dtopi(double x) {return x*pi1;}
double pitod(double x) {return x*pi2;}
int sgn(double x) 
{
    if(fabs(x)<eps) return 0;	// x == 0, 精度范围内的近似相等
    return x>0?1:-1;			// 返回正负
}

typedef struct point 
{
    double x,y;
    point(double x = 0, double y = 0) : x(x), y(y) {}
    double operator * (point b) {return x*b.x+y*b.y;}//点乘
	double operator ^ (point b) {return x*b.y-y*b.x;}//叉乘
	point operator + (point b) {return point(x+b.x,y+b.y);}
	point operator - (point b) {return point(x-b.x,y-b.y);}
	bool operator == (const point &b) const {return sgn(x-b.x)==0&&sgn(y-b.y)==0;}
	bool operator < (const point &b) const {return sgn(x-b.x)==0?sgn(y-b.y)<0:x<b.x;}
	bool operator > (point b) {return !(*this<b);}
	point operator * (double k) {return point(k*x,k*y);}//数乘
	point operator / (double k) {return point(x/k,y/k);}//数除
    double len() {return hypot(x,y);}//模长
	double len2() {return x*x+y*y;}//模长平方
	point trunc(double r) {double l=len();r/=l;return point(x*r,y*r);}//变模长为r
	double dis(point b){return hypotl(x-b.x,y-b.y);}
	double angle() {return atan2(y,x);}
	int quad() {return sgn(y)>0||sgn(y)==0&&sgn(x)>0;}//0:[-π,0)  1:[0,π)
	point unit() {return *this/len();}//单位向量
}Vector;
double len(Vector a) {return sqrtl(a*a);}//模长
double dis(point a,point b) {return (a-b).len();}
double dis2(point a,point b) {return (a-b).len2();}
double norm(double x)//返回弧度[0,2π)
{
    while(x<0) x+=2*pi;
    while(x>=2*pi) x-=2*pi;
    return x;
}

double angle(Vector a,Vector b)//a到b的夹角
{
    double t=acos((a*b)/len(a)/len(b));
    return t;           // 返回 [0,π]
    //return pitod(t);  // 返回 [0,180]
}

double rad(Vector a,Vector b)//角aob弧度大小
{
	return fabs(atan2(fabs(a^b),a*b));
}

point rotleft(point a) {return point(-a.y,a.x);}//逆时针旋转90度
point rotright(point a) {return point(a.y,-a.x);}//顺时针旋转90度
point rotate(point a,point o,double angle)//点a绕点p逆时针旋转弧度angle [0,π]
{
	point v=a-o;
	double c=cos(angle),s=sin(angle);
	return point(o.x+v.x*c-v.y*s,o.y+v.x*s+v.y*c);
}
Vector Rotate(Vector a,double angle)//向量旋转弧度angle [0,π]
{
    Vector b(sin(angle),cos(angle));
    return Vector(a^b,a*b);
}

//1:  b在a的逆时针方向
//-1: b在a的顺时针方向
//2:  b与a同向共线
//-2: b在a反向共线
int cross(Vector a,Vector b)//向量b与a的方位关系
{
	int x=sgn(a^b),y=sgn(a*b);
	if(x!=0) return x;
	else return 2*y;
}
bool sameline(point a,point b,point c) {return sgn((b-a)^(c-b))==0;}//三点共线
double cross(point a,point b,point c) {return (b-a)^(c-a);}//ab叉乘ac
double dot(point a,point b,point c) {return (b-a)*(c-a);}//ab点乘ac

typedef struct line
{
	point s,e;
	line(){}
	line(point _s,point _e) {s =_s; e= _e;}
	line(point p,double angle)//点斜
	{
		s=p;
		if(sgn(angle-pi/2)==0)  e=(s+point(0,1));
		else e=(s+point(1,tan(angle)));
	}
	line(double a,double b,double c)//ax+by+c=0;
	{
		if(sgn(a)==0) {s=point(0,-c/b);e=point(1,-c/b);}
		else if(sgn(b)==0) {s=point(-c/a,0);e=point(-c/a,1);}
		else {s=point(0,-c/b);e=point(1,(-c-a)/b);}
	}
	double length() {return s.dis(e);}//线段长度
	double angle1()//返回[0,π]的基于x轴的斜倾角(弧度制)
	{
		double k=atan2(e.y-s.y,e.x-s.x);
		if(sgn(k)<0) k+=pi;
		if(sgn(k-pi)==0) k-=pi;
		return k;
	}
	double angle2()//返回(-π,π]的基于x正半轴的斜倾角(弧度制)
	{
		return atan2(e.y-s.y,e.x-s.x);
	}
}seg;

//-1: 在右侧(顺时针)
//1:  在左侧(逆时针)
//0:  在直线上
int relation_p_l(point p,line l) {return sgn((p-l.s)^(l.e-l.s));}//点与直线关系

double dis_p_l(point p,line l) {return fabs((p-l.s)^(l.e-l.s))/l.length();}//点到直线的距离

point prog(point p,line l)//点p在直线l上的投影点(垂足)
{
	point x=l.e-l.s;
	return l.s+((x*(x*(p-l.s)))/(x.len2()));
}

point mirror(point p,line l)//点p在直线l上的对称点
{
	point q=prog(p,l);
	return point(2*q.x-p.x,2*q.y-p.y);
}

bool relation_p_seg(point p,seg l)//点是否在线段上
{
	return sgn((p-l.s)^(l.e-l.s))==0&&sgn((p-l.s)*(p-l.e))<=0;
}

double dis_p_seg(point p,seg l)//点到线段的距离
{
	if(sgn((p-l.s)*(l.e-l.s))<0||sgn((p-l.e)*(l.s-l.e))<0)
		return min(p.dis(l.s),p.dis(l.e));
	return dis_p_l(p,l);
}

bool parallel(line l,line v) {return sgn((l.e-l.s)^(v.e-v.s))==0;}//判断平行

//0:  平行
//1:  共线
//-1: 相交
int relation_l_l(line l,line v)//判断两直线的位置关系
{
	if(parallel(l,v)) return relation_p_l(l.s,v)==0;
	return -1;
}

//-1: 规范相交
//1:  非规范相交(顶点处相交)
//0:  不相交
int relation_l_seg(line l,seg v)//直线与线段位置关系
{
	int d1=sgn((l.e-l.s)^(v.s-l.s));
	int d2=sgn((l.e-l.s)^(v.e-l.s));
	if((d1^d2)==-2) return -1;
	return (d1==0||d2==0);
}

//-1: 规范相交(恰有一个交点且非端点,即互相穿过)
//1:  非规范相交
//0:  不相交
int is_segcrossseg(seg l,seg v)//两线段相交判断
{
	int d1=sgn((l.e-l.s)^(v.s-l.s));
	int d2=sgn((l.e-l.s)^(v.e-l.s));
	int d3=sgn((v.e-v.s)^(l.s-v.s));
	int d4=sgn((v.e-v.s)^(l.e-v.s));
	if ((d1^d2)==-2&&(d3^d4)==-2) return -1;
	
	return (d1==0&&sgn((v.s-l.s)*(v.s-l.e))<=0)||
	(d2==0&&sgn((v.e-l.s)*(v.e-l.e))<=0)||
	(d3==0&&sgn((l.s-v.s)*(l.s-v.e))<=0)||
	(d4==0&&sgn((l.e-v.s)*(l.e-v.e))<=0);
}

double dis_seg_seg(seg l,seg v)//线段到线段的距离
{
	if(is_segcrossseg(l,v)) return 0; 
	return min(min(dis_p_seg(v.s,l),dis_p_seg(v.e,l)),min(dis_p_seg(l.s,v),dis_p_seg(l.e,v)));
}

point lcrossl(line a,line b)//求两直线的交点(需要保证直线不平行或共线)
{	
	point u=a.s-b.s,v=a.e-a.s,w=b.e-b.s;

	//***************************
	if((w^v)==0)//o2优化出问题的时候直接返回mle,
	{
		vector<int>q;
		while(1) q.push_back(1);
	}
	//***************************

  	double t=(u^w)/(w^v);
  	return a.s+v*t;
}

point add[4];
int num=0;
void solve()
{
	num++;
    int n;
	cin>>n;
	point a[n+1];
	for(int i=1;i<=n;i++)
	{
		ll x,y;
		cin>>x>>y;
		a[i]={x,y};
	}
	vector<line>stl;
	vector<point>stp;
	for(int i=0;i<4;i++) stl.push_back(line(a[1],a[1]+add[i]));
	for(int i=2;i<=n;i++)
	{
		vector<point>nwp;
		vector<line>nwl,nwll;
		for(int j=0;j<4;j++) nwl.push_back(line(a[i],a[i]+add[j]));
		for(auto p:stp)
		{
			int fact=0;
			for(auto v:nwl)
			{
				if(relation_p_l(p,v)==0) fact=1;
			}
			if(fact) nwp.push_back(p);
		}
		for(auto p:stl)
		{
			for(auto v:nwl)
			{
				if(relation_l_l(p,v)==1)
				{
					nwll.push_back(p);
				}
				else if(relation_l_l(p,v)==-1)
				{
					nwp.push_back(lcrossl(p,v));
				}
			}
		}
		stp=nwp;
		stl=nwll;
	}
	if(stp.size())
	{
		cout<<"YES"<<endl;
		//if(num==317&&sgn(stp[0].x-2)==0) cout<<"123456789 123456789"<<endl;
		cout<<fixed<<setprecision(0)<<stp[0].x<<" "<<stp[0].y<<endl;
	}
	else if(stl.size())
	{
		cout<<"YES"<<endl;
		//if(num==317&&sgn(stl[0].s.x-2)==0) cout<<"123456 123456"<<endl;
		cout<<fixed<<setprecision(0)<<stl[0].s.x<<" "<<stl[0].s.y<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
	//for(auto [x,y]:stp) cout<<x<<" "<<y<<" ";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);

	int T=1;
	cin>>T;

	add[0]={1,0};
	add[1]={0,1};
	add[2]={1,1};
	add[3]={1,-1};

	while(T--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3944kb

input:

3
2
1 1
2 2
4
0 1
1 0
3 1
4 0
5
0 1
1 0
1 2
2 2
4 2

output:

YES
2 1
NO
YES
1 2

result:

ok OK (3 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

1
4
-100000000 -100000000
100000000 -100000000
-100000000 100000000
100000000 100000000

output:

YES
100000000 -100000000

result:

ok OK (1 test case)

Test #3:

score: 0
Accepted
time: 1ms
memory: 3936kb

input:

330
3
5 1
-3 -5
-2 2
2
1 4
4 0
4
2 -5
3 -3
-5 4
2 -2
2
-4 1
2 4
1
1 5
4
3 5
-2 3
5 2
-3 -3
5
-3 -4
2 -1
-2 -2
1 0
-1 -5
5
4 -3
-2 -4
2 2
0 -5
-4 -3
4
0 0
-3 -5
0 5
5 0
1
1 -1
5
0 2
3 4
1 4
4 5
5 0
3
-4 -5
-5 -3
5 -5
3
-1 2
-4 -4
-1 5
4
1 1
4 5
-1 0
5 2
1
-3 2
5
5 0
4 1
-3 -5
3 -3
0 0
5
0 1
-5 4
-5 5...

output:

YES
-3 1
YES
4 4
YES
2 -3
YES
2 1
YES
1 5
NO
NO
NO
YES
0 -5
YES
1 -1
NO
YES
-5 -5
YES
-4 2
YES
1 2
YES
-3 2
NO
YES
-5 -4
YES
2 0
YES
-5 -3
YES
-2 0
NO
YES
2 0
YES
0 -1
YES
5 1
YES
0 -1
YES
1 5
YES
-5 -2
YES
4 6
NO
YES
5 -4
NO
YES
1 -4
YES
3 5
YES
-1 3
YES
-5 1
NO
NO
YES
2 5
YES
2 4
YES
1 -4
YES
-2 -...

result:

ok OK (330 test cases)

Test #4:

score: -100
Wrong Answer
time: 53ms
memory: 4008kb

input:

33773
4
-2 -5
4 -1
-5 4
2 -1
3
5 1
1 0
-2 4
1
-5 -4
4
-3 1
5 -1
1 -2
-3 5
2
-2 -2
0 2
4
-2 -1
4 -5
1 1
1 -4
3
-5 -5
-5 0
-3 -5
1
-3 0
4
-5 -4
2 2
-5 -3
5 -3
1
-5 0
2
-3 -3
-4 -3
1
3 -2
3
-2 -2
5 -4
5 -3
2
5 -1
-5 2
4
0 -1
5 1
0 0
-4 -1
1
-5 4
4
-5 3
3 0
-1 -3
0 3
2
4 0
0 -3
2
-2 4
0 1
2
-3 3
4 1
3
-...

output:

NO
YES
1 1
YES
-5 -4
NO
YES
0 -2
NO
YES
-5 -5
YES
-3 0
NO
YES
-5 0
YES
-4 -3
YES
3 -2
YES
5 -2
YES
-5 -1
NO
YES
-5 4
NO
YES
0 0
YES
0 4
YES
4 3
YES
-2 -3
NO
YES
0 1
YES
3 5
NO
NO
YES
0 0
YES
-4 -4
YES
2 -3
YES
4 -5
YES
0 3
YES
4 4
NO
YES
-3 3
NO
YES
1 -3
YES
-3 5
NO
NO
YES
2 1
NO
YES
-3 1
YES
1 -1
N...

result:

wrong answer Queen (4, 1) does not attack square (2, 4) (test case 317)