您的位置:首页 > 其它

ICPC 6921 Refraction

2015-09-03 13:11 302 查看


一个水槽如图

Input

First line of the input file contains an integer T (0 < T < 100001) which denotes the number of test cases. Each of the next T lines contains the input for one test case. Each line contains 5 integers W (100 ≤ W ≤ 1000), H (100 ≤ H ≤ 1000), x (1 ≤ x < W), xe(
W < xe ≤ 2000), ye (H < ye ≤ 2000) and a floating-point number µ (1.1000 ≤ µ ≤ 5.0000). The meaning of these symbols are given in the problem statement.



题意:判断一个点能不能被看到,如果能,输出水位最低高度

这题,二分高度不可以,有精度问题。应该从(X,0)点出发,假设水位高度,然后刚好能连到眼睛画线。

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: