题解 | #E#

Experiment Class

https://ac.nowcoder.com/acm/contest/17574/E

E题题解 稍后更新

先放个代码
#include<iostream>
#include<cmath>
#include<iomanip>

using
		namespace
					std;

signed main(){
	double a,b,c,d,x0,y0,x1,y1;
	cin>>a>>b>>c>>d>>x0>>y0>>x1>>y1;
	double s1x,s1y,s2x,s2y,t1x,t1y,t2x,t2y;
	double tanab,tancd,tans,tant;
	
	tanab=b/a;
	tancd=d/c;
	tans=y0/x0; 
	tant=y1/x1;
	
	if((tans>tanab&&tans>tancd)||(tant>tanab&&tant>tancd)||(tans<tanab&&tans<tancd)||(tant<tanab&&tant<tancd)){
		if(((tans>tanab&&tans>tancd)||(tans<tanab&&tans<tancd))^((tant>tanab&&tant>tancd)||(tant<tanab&&tant<tancd))){
			if(((tans>tanab&&tans>tancd)||(tans<tanab&&tans<tancd))){
				if(tans>tanab&&tans>tancd){
					if(tanab>tancd){
						s2x=((c*c-d*d)*x0+2*c*d*y0)/(c*c+d*d);
						s2y=((d*d-c*c)*y0+2*c*d*x0)/(c*c+d*d);
						cout<<fixed<<setprecision(3)<<sqrt((s2x-x1)*(s2x-x1)+(s2y-y1)*(s2y-y1));
					}
					else{
						s1x=((a*a-b*b)*x0+2*a*b*y0)/(a*a+b*b);
						s1y=((b*b-a*a)*y0+2*a*b*x0)/(a*a+b*b);
						cout<<fixed<<setprecision(3)<<sqrt((s1x-x1)*(s1x-x1)+(s1y-y1)*(s1y-y1));
					}
				}
				else{
					if(tanab>tancd){
						s1x=((a*a-b*b)*x0+2*a*b*y0)/(a*a+b*b);
						s1y=((b*b-a*a)*y0+2*a*b*x0)/(a*a+b*b);
						cout<<fixed<<setprecision(3)<<sqrt((s1x-x1)*(s1x-x1)+(s1y-y1)*(s1y-y1));
					}
					else{
						s2x=((c*c-d*d)*x0+2*c*d*y0)/(c*c+d*d);
						s2y=((d*d-c*c)*y0+2*c*d*x0)/(c*c+d*d);
						cout<<fixed<<setprecision(3)<<sqrt((s2x-x1)*(s2x-x1)+(s2y-y1)*(s2y-y1));
					}
				}
			}
			else{//(((tant>tanab&&tant>tancd)||(tans<tanab&&tans<tancd))){
				if(tant>tanab&&tant>tancd){
					if(tanab>tancd){
						t2x=((c*c-d*d)*x1+2*c*d*y1)/(c*c+d*d);
						t2y=((d*d-c*c)*y1+2*c*d*x1)/(c*c+d*d);
						cout<<fixed<<setprecision(3)<<sqrt((t2x-x0)*(t2x-x0)+(t2y-y0)*(t2y-y0));
					}
					else{
						t1x=((a*a-b*b)*x1+2*a*b*y1)/(a*a+b*b);
						t1y=((b*b-a*a)*y1+2*a*b*x1)/(a*a+b*b);
						cout<<fixed<<setprecision(3)<<sqrt((t1x-x0)*(t1x-x0)+(t1y-y0)*(t1y-y0));
					}
				}
				else{
					if(tanab>tancd){
						t1x=((a*a-b*b)*x1+2*a*b*y1)/(a*a+b*b);
						t1y=((b*b-a*a)*y1+2*a*b*x1)/(a*a+b*b);
						cout<<fixed<<setprecision(3)<<sqrt((t1x-x0)*(t1x-x0)+(t1y-y0)*(t1y-y0));
					}
					else{
						t2x=((c*c-d*d)*x1+2*c*d*y1)/(c*c+d*d);
						t2y=((d*d-c*c)*y1+2*c*d*x1)/(c*c+d*d);
						cout<<fixed<<setprecision(3)<<sqrt((t2x-x0)*(t2x-x0)+(t2y-y0)*(t2y-y0));
					}
				}
			}
		}
		else{
			if((tans>tanab&&tans>tancd)^(tant>tanab&&tant>tancd)){
				cout<<fixed<<setprecision(3)<<sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
			}
			else{
				if((tans>tanab&&tans>tancd)&&(tant>tanab&&tant>tancd)){
					if(tanab>tancd){
						s2x=((c*c-d*d)*x0+2*c*d*y0)/(c*c+d*d);
						s2y=((d*d-c*c)*y0+2*c*d*x0)/(c*c+d*d);
						cout<<fixed<<setprecision(3)<<sqrt((s2x-x1)*(s2x-x1)+(s2y-y1)*(s2y-y1));
					}
					else{
						s1x=((a*a-b*b)*x0+2*a*b*y0)/(a*a+b*b);
						s1y=((b*b-a*a)*y0+2*a*b*x0)/(a*a+b*b);
						cout<<fixed<<setprecision(3)<<sqrt((s1x-x1)*(s1x-x1)+(s1y-y1)*(s1y-y1));
					}
				}
				else{
					if(tanab>tancd){
						s1x=((a*a-b*b)*x0+2*a*b*y0)/(a*a+b*b);
						s1y=((b*b-a*a)*y0+2*a*b*x0)/(a*a+b*b);
						cout<<fixed<<setprecision(3)<<sqrt((s1x-x1)*(s1x-x1)+(s1y-y1)*(s1y-y1));
					}
					else{
						s2x=((c*c-d*d)*x0+2*c*d*y0)/(c*c+d*d);
						s2y=((d*d-c*c)*y0+2*c*d*x0)/(c*c+d*d);
						cout<<fixed<<setprecision(3)<<sqrt((s2x-x1)*(s2x-x1)+(s2y-y1)*(s2y-y1));
					}
				}
			}
		}
	}
	else{
		s1x=((a*a-b*b)*x0+2*a*b*y0)/(a*a+b*b);
		s1y=((b*b-a*a)*y0+2*a*b*x0)/(a*a+b*b);
		s2x=((c*c-d*d)*x0+2*c*d*y0)/(c*c+d*d);
		s2y=((d*d-c*c)*y0+2*c*d*x0)/(c*c+d*d);
		t1x=((a*a-b*b)*x1+2*a*b*y1)/(a*a+b*b);
		t1y=((b*b-a*a)*y1+2*a*b*x1)/(a*a+b*b);
		t2x=((c*c-d*d)*x1+2*c*d*y1)/(c*c+d*d);
		t2y=((d*d-c*c)*y1+2*c*d*x1)/(c*c+d*d);
		double l1=sqrt((s1x-t2x)*(s1x-t2x)+(s1y-t2y)*(s1y-t2y));
		double l2=sqrt((s2x-t1x)*(s2x-t1x)+(s2y-t1y)*(s2y-t1y));
		cout<<fixed<<setprecision(3)<<min(l1,l2);
	}
	return EOF+1;
}


全部评论

相关推荐

一名愚蠢的人类:多少games小鬼留下了羡慕的泪水
投递荣耀等公司10个岗位
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务