【BZOJ】3621: 我想那还真是令人高兴啊

http://www.lydsy.com/JudgeOnline/problem.php?id=3621

题意:给两个三角形,问A能否通过旋转伸缩到B。

#include <bits/stdc++.h>
using namespace std;
struct cp {
	static const double eps=1e-4;
	double x, y;
	cp(double _x=0, double _y=0) : x(_x), y(_y) {}
	void scan() { scanf("%lf%lf", &x, &y); }
	void P() const { printf("%.9f %.9f\n", x, y); }
	cp operator - (const cp &a) { return cp(x-a.x, y-a.y); }
	cp operator * (const cp &a) { return cp(x*a.x-y*a.y, x*a.y+y*a.x); }
	cp operator / (const cp &a) { static double c; c=a.x*a.x+a.y*a.y; return cp((x*a.x+y*a.y)/c, (y*a.x-x*a.y)/c); }
	bool operator == (const cp &a) { return abs(x-a.x)<eps && abs(y-a.y)<eps; }
}a[2][3], ans;
int vis[3], b[3];
bool check() {
	static cp T, P;
	T=(a[1][b[0]]-a[1][b[1]])/(a[0][0]-a[0][1]);
	P=(a[1][b[0]]-a[0][0]*T)/(cp(1)-T);
	if((a[0][2]-P)*T==a[1][b[2]]-P) {
		ans=P;
		return 1;
	}
	return 0;
}
bool dfs(int x) {
	if(x==3) return check();
	for(int i=0; i<3; ++i) if(!vis[i]) {
		vis[i]=1; b[x]=i;
		if(dfs(x+1)) return 1;
		vis[i]=0;
	}
	return 0;
}
int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		for(int i=0; i<2; ++i)
			for(int j=0; j<3; ++j)
				a[i][j].scan();
		memset(vis, 0, sizeof vis);
		if(!dfs(0)) puts("-1");
		else ans.P();
	}
	return 0;
}

  

复数乘法的几何意义就是极角相加,长度相乘。因此当做复平面来做就行辣= =

posted @ 2015-03-26 17:09  iwtwiioi  阅读(314)  评论(0编辑  收藏  举报