思路:
你可以求出白球要移動到哪個點,同時白球和紅球分別在紅線兩邊纔可能進行移動。
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
const int maxn = 4e5 + 7;
const double PI = acos(-1);
const double eps = 1e-6;
int sign(double x) {
if(x > 0) return 1;
else if(x < 0) return -1;
else return 0;
}
double Get(double x,double y,double nx,double ny,double k) {
return k * x - y + ny - k * nx;
}
int main() {
int T;scanf("%d",&T);
while(T--) {
double wx,wy,rx,ry,hx,hy;
scanf("%lf%lf%lf%lf%lf%lf",&wx,&wy,&rx,&ry,&hx,&hy);
double k1 = (hy - ry) / (hx - rx);
double deg1 = atan2(ry - hy,rx - hx);
double nx,ny;
nx = rx + 2 * cos(deg1);
ny = ry + 2 * sin(deg1);
double k2 = -1.0 / k1;
if(sign(Get(wx,wy,nx,ny,k2)) == sign(Get(rx,ry,nx,ny,k2))) {
printf("Impossible\n");
}
else {
double ans = atan2(ny - wy,nx - wx);
if(ans < 0) ans += 2 * PI;
printf("%.6f\n",ans / PI);
}
}
return 0;
}