HDU3365(幾何計算)

題解:以A0與A1,B0與B1兩條直線爲標準判斷選擇的幾度,變長了幾倍,最後用根據這個求A0與Ai變了幾度幾倍移動到B0即可

#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<cstdlib>
#include<ctime>
#include<stack>
using namespace std;
#define mes(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(i = a; i <= b; i++)
#define dec(i,a,b) for(i = b; i >= a; i--)
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define mid (L+R)/2
#define lson ls,L,mid
#define rson rs,mid+1,R
typedef double db;
typedef long long int ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int mx = 1e5+5;
const int x_move[] = {1,-1,0,0,1,1,-1,-1};
const int y_move[] = {0,0,1,-1,1,-1,1,-1};
int n,m;
struct point{
	db x,y;
}a[mx],b[mx];
db disa[mx],disb[mx];
db dist(point a,point b){
	db x = a.x-b.x;
	db y = a.y-b.y;
	return sqrt(x*x+y*y);
}
db angle(point a,point b){
	db x = a.x-b.x;
	db y = a.y-b.y;
	db ans = x/sqrt(x*x+y*y);
	ans = acos(ans);
	if(a.y<b.y)
		ans = 2*acos(-1.0)-ans;
	return ans;
}
int main(){
	int t,ca = 1;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i = 1; i <= n; i++)
			scanf("%lf%lf",&a[i].x,&a[i].y);
		for(int i = 2; i <= n; i++)
			disa[i] = dist(a[i],a[1]);
		scanf("%lf%lf%lf%lf",&b[1].x,&b[1].y,&b[2].x,&b[2].y);
		disb[2] = dist(b[2],b[1]);
		db d = disb[2]/disa[2];
		for(int i = 3; i <= n; i++)
			disb[i] = disa[i]*d;
		db s = angle(b[2],b[1])-angle(a[2],a[1]);
		for(int i = 3; i <= n; i++){
			db tmp = angle(a[i],a[1]);
			tmp += s;
			if(tmp>=2*acos(-1.0))
				tmp -= 2*acos(-1.0);
			if(tmp<0)
				tmp += 2*acos(-1);
			b[i].x = b[1].x+cos(tmp)*disb[i];
			b[i].y = b[1].y+sin(tmp)*disb[i];
		}
		printf("Case %d:\n",ca++);
		for(int i = 1; i <= n; i++)
			printf("%.2lf %.2lf\n",b[i].x,b[i].y);
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章