题目:
题目大意:求最少的水面高度,另眼睛所在位置能看到物体。
题目思路:
经过P点黑色直线为水面高度为0时,且经过A点。
经过P点直线为经过x点根据u折射的直线,这可得P点高度是所需求h。
1.先求出角1的sin值
2.求出角1的tan值
3.根据三角形1和2相似,得出PH = (xe - W) * (H - h) / (ye - H),可知DE = W - PH - x;
4.化简方程组 h = ( W - PH - x) / tan_n;
如果h大于H,可知不存在h;如果h <= 0,h = 0;另外则输出h;
题目链接:6921 - Refraction
以下是代码:
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
const double EPS = 3 * 1e-6;
int main(){
int t;
cin >> t;
while(t--)
{
double W,H,x,xe,ye;
double u;
cin >> W >> H >> x >> xe >> ye >> u;
double sin_n = (xe - W) / sqrt((xe - W) * (xe - W) + (ye - H) * (ye - H)) / u;
double tan_n = sin_n / sqrt(1 - sin_n * sin_n);
double h = (((ye - H) * W - (ye - H) * x - H * (xe - W))) / ((ye - H) * tan_n - (xe - W));
if (h <= 0) h = 0;
if (h > H)
printf("Impossible\n");
else
printf("%.4lf\n",h);
}
}
return 0;
}