Deepest Station
题意:三维空间给两个点,问能否利用两条与地面夹角为45度的扶梯到达。
解法:其实可以利用投影,且45度的话底和高一样长,然后直接算就好。
#include <iostream>
using namespace std;
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double sqr(double x) {
return x*x;
}
int main() {
freopen("deepest.in","r",stdin);
freopen("deepest.out","w",stdout);
double x, y, d;
cin >> x >> y >> d;
double len = sqrt(x*x+y*y);
if (fabs(len-d) < 1e-8) {
cout << "Single staircase" << endl;
} else if (len - d > 1e-8) {
cout << "Impossible" << endl;
} else {
double s=d-len;
double h=sqrt(s*s/2);
h=sqrt(h*h/2);
double z=d-h;
x=x*z/len;
y=y*z/len;
printf("%.10lf %.10lf %.10lf\n", x, y, h);
}
fclose(stdin);fclose(stdout);
}