萌新刚学OI,求帮忙Debug
  • 板块CF13B Letter A
  • 楼主辰星凌
  • 当前回复10
  • 已保存回复10
  • 发布时间2020/5/29 20:34
  • 上次更新2023/11/7 01:30:17
查看原帖
萌新刚学OI,求帮忙Debug
110985
辰星凌楼主2020/5/29 20:34

一道算几水题WA到怀疑人生

似乎不是精度问题,因为换成long double也过不了

CF上只有样例和一组看不全的大数据

网上题解都太奇葩了看不懂

自闭ing...

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LD double
#define LL long long
#define Vector Point
#define Re register int
using namespace std;
const int N=1003,inf=2e9;
const LD eps=1e-8;
inline int dcmp(LD a){return a<-eps?-1:(a>eps?1:0);}
inline void in(Re &x){
    int f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
struct Point{
    LD x,y;Point(LD X=0,LD Y=0){x=X,y=Y;}
    inline void In(){scanf("%lf%lf",&x,&y);}
}P1[4],P2[4];
inline LD Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
inline LD Cro(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
inline LD Len(Vector a){return sqrt(Dot(a,a));}
inline Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
inline Vector operator-(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
inline Vector operator*(Vector a,LD b){return Vector(a.x*b,a.y*b);}
inline bool operator==(Vector a,Vector b){return !dcmp(a.x-b.x)&&!dcmp(a.y-b.y);}
inline bool operator!=(Vector a,Vector b){return dcmp(a.x-b.x)||dcmp(a.y-b.y);}
inline int pan_PL(Point p,Point a,Point b){
	return !dcmp(Cro(p-a,p-b))&&dcmp(Dot(p-a,p-b))<=0;
}
inline Point cross_LL(Point a,Point b,Point c,Point d){
	Vector x=b-a,y=d-c,z=a-c;
	return a+x*(Cro(y,z)/Cro(x,y));
}
inline int judge(Re i,Re j,Re k){
//	printf("i=%d, j=%d, k=%d:\n",i,j,k);
	if(!dcmp(Cro(P2[i]-P1[i],P2[j]-P1[j]))||!dcmp(Cro(P2[i]-P1[i],P2[k]-P1[k]))||!dcmp(Cro(P2[j]-P1[j],P2[k]-P1[k])))return 0;//共线
	Point P=cross_LL(P1[i],P2[i],P1[j],P2[j]);//前两条直线交点
	if((P!=P1[i]&&P!=P2[i])||(P!=P1[j]&&P!=P2[j]))return 0;//i,j无公共端点
	if(P1[i]==P)swap(P1[i],P2[i]);if(P1[j]==P)swap(P1[j],P2[j]);
	
	if(dcmp(Dot(P1[i]-P,P1[j]-P))<=0)return 0;//角度>=90
//	printf("P=(%.2lf,%.2lf), P1[i]=(%.2lf,%.2lf), P1[j]=(%.2lf,%.2lf)\n",P.x,P.y,P1[i].x,P1[i].y,P1[j].x,P1[j].y);
//	printf("P1[k]=(%.2lf,%.2lf), P2[k]=(%.2lf,%.2lf)\n",P1[k].x,P1[k].y,P2[k].x,P2[k].y);
	Point A=cross_LL(P,P1[i],P1[k],P2[k]);
//	printf("A=(%.2lf,%.2lf)\n",A.x,A.y);
	if((A!=P1[k]&&A!=P2[k])||!pan_PL(A,P,P1[i]))return 0;//k无端点在i上
	LD len1=Len(P-A),len2=Len(P1[i]-A);if(len1>len2)swap(len1,len2);
//	printf("len1=%lf, len2=%lf\n",len1,len2);
	if(dcmp(len1*4.0-len2)<0)return 0;//未满足len1>=len2/4
	
	A=cross_LL(P,P1[j],P1[k],P2[k]);
//	printf("A=(%.2lf,%.2lf)\n",A.x,A.y);
	if((A!=P1[k]&&A!=P2[k])||!pan_PL(A,P,P1[j]))return 0;//k无端点在j上
	len1=Len(P-A),len2=Len(P1[j]-A);if(len1>len2)swap(len1,len2);
//	printf("len1=%lf, len2=%lf\n",len1,len2);
	if(dcmp(len1*4.0-len2)<0)return 0;//未满足len1>=len2/4
//	puts("ok");
	return 1;
}
inline int sakura(){
	return judge(3,2,1)||judge(1,3,2)||judge(1,2,3);
}
int T;
int main(){
//	freopen("456.txt","r",stdin);
	in(T);
	while(T--){
		for(Re i=1;i<=3;++i)P1[i].In(),P2[i].In();
		puts(sakura()?"YES":"NO");
	}
}
2020/5/29 20:34
加载中...