結果

問題 No.1175 Simultaneous Equations
ユーザー 沙耶花沙耶花
提出日時 2020-08-21 21:21:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,154 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 199,664 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 07:22:45
合計ジャッジ時間 3,352 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 2000000005
const double eps = 1e-10;

template <typename T>
struct vector_2d{
	T x,y,r,d;
	
	vector_2d(T a=0.0,T b=0.0){
		x = a;
		y = b;
		fix_rd();
	}
	
	void update_x(T a,T b){
		x = a*x + b;
		fix_rd();
	}
	
	void update_x(T a){
		update_x(0.0,a);
	}
	
	void update_y(T a,T b){
		y = a*y + b;
		fix_rd();
	}
	
	void update_y(T a){
		update_y(0.0,a);
	}
	
	void update_r(T a,T b){
		r = a*r + b;
		fix_xy();
	}
	
	void update_r(T a){
		update_r(0.0,a);
	}
	
	void update_d(T a,T b){
		d = a*d + b;
		fix_xy();
	}

	void update_d(T a){
		update_d(0.0,a);
	}
	
	void fix_xy(){
		x = r * cos(d);
		y = r * sin(d);
		fix_rd();
	}
	
	void fix_rd(){
		r = hypot(x,y);
		if(r==0.0)d=0.0;
		else d = atan2(y,x);
		fix_zero();
	}
	
	void fix_zero(){
		if(abs(x)<eps)x = 0.0;
		if(abs(y)<eps)y = 0.0;
		if(abs(r)<eps)r = 0.0;
		if(abs(d)<eps)d = 0.0;
	}
	
	
	T get_dis(vector_2d<T> V){
		return hypot(x-V.x,y-V.y);
	}
	
	T angle_difference(vector_2d<T> V){
		double ret = d - V.d;
		if(ret<-acos(-1.0))ret = acos(-1.0)*2.0+ret;
		if(ret>acos(-1.0))ret=-acos(-1.0)*2.0+ret;
		return ret;
	}
	
	//中点
	vector_2d get_midpoint(vector_2d<T> V){
		V.update_x(0.5,x/2.0);
		V.update_y(0.5,y/2.0);
		return V;
	}
	
	T get_inner_product(vector_2d<T> V){
		return x*V.x+y*V.y;
	}
	
	T get_cross_product(vector_2d<T> V){
		return x*V.y-y*V.x;
	}
	
	vector_2d &operator+=(const vector_2d<T> &another){
		update_x(1,another.x);
		update_y(1,another.y);
		return (*this);
	}
	
	vector_2d &operator-=(const vector_2d<T> &another){
		update_x(1,-another.x);
		update_y(1,-another.y);
		return (*this);
	}
	
	vector_2d operator+(const vector_2d<T> &another)const{
		return (vector_2d(*this)+=another);
	}
	
	vector_2d operator-(const vector_2d<T> &another)const{
		return (vector_2d(*this)-=another);
	}
	
	void show(){
		cout<<x<<','<<y<<endl;
	}
};

//ax+by+c=0
template <typename T>
struct line{
	T a,b,c;
	line(T A,T B,T C){
		a=A,b=B,c=C;
	}
	
	line(vector_2d<T> V,T A,T B){
		a = A;
		b = B;
		c = -a*V.x - b*V.y;
	}
	
	line(vector_2d<T> V1=vector_2d<T>(),vector_2d<T> V2=vector_2d<T>()):line(V1,-(V1.y-V2.y),V1.x-V2.x){
	}

	
	void fix_abc(){
		T l = hypot(a,b);
		a/=l;b/=l;c/=l;
		T X = a;
		if(abs(X)<eps)X=b;
		if(abs(X)<eps)X=c;
		if(X<0.0){
			a*=-1;
			b*=-1;
			c*=-1;
		}
	}
	
	T get_signed_dis(vector_2d<T> V){
		return (a*V.x+b*V.y+c)/hypot(a,b);
	}
	
	T get_dis(vector_2d<T> V){
		return abs(get_signed_dis(V));
	}
	
	vector_2d<T> get_projection(vector_2d<T> P){
		line L(P,-b,a);
		return get_cross_point(L);
	}
	
	vector_2d<T> get_cross_point(line<T> L){
		vector_2d<T> ret(1e20,1e20);

		if(abs(L.a*b-a*L.b)>=eps){
			ret.update_x((L.b*c-b*L.c)/(L.a*b-a*L.b));
			ret.update_y((a*L.c-L.a*c)/(L.a*b-a*L.b));
		}

		return ret;
	}
	
	void show(){
		cout<<a<<','<<b<<','<<c<<endl;
	}
	
};

int main(){
	
	double a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	
	line<double> L0(a,b,-c),L1(d,e,-f);
	
	vector_2d<double> ret = L0.get_cross_point(L1);
	
	cout<<fixed<<setprecision(10)<<ret.x<<' '<<ret.y<<endl;
	
	
	return 0;
}
0