UVALive 6092 Catching Shade in Flatland

https://icpcarchive.ecs.baylor.edu/external/60/6092.pdf


坐标上有很多相离圆,问一条可以绕原点旋转的线段与这些圆相交的最长弦长之和。

直接模拟即可。注意是线段。


#include<iostream>  
#include<algorithm>
#include<math.h>
#include<cstdio>
using namespace std;

int main()
{
	int n, a[500], b[500], r[500];
	while (cin >> n, n)
	{
		for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> r[i];
		double maxn = 0;
		for (int i = 0; i < 24 * 60; i++)
		{
			double k = asin(1.0)*(i / 360.0), sum = 0;
			for (int j = 0; j < n; j++)
			if ((i / 360 == 0 || i / 360 == 3) && a[j] + b[j] * tan(k)>0 || (i / 360 == 1 || i / 360 == 2) && a[j] + b[j] * tan(k) < 0)
			{
				double dis = -2 * tan(k) *a[j] * b[j] + b[j] * b[j] - a[j] * a[j];
				dis = a[j] * a[j] + dis / (tan(k)*tan(k) + 1);
				if (dis < r[j] * r[j]) sum += 2 * sqrt(r[j] * r[j] - dis);
			}
			maxn = max(maxn, sum);
		}
		printf("%.3lf\n", maxn);
	}
	return 0;
}



你可能感兴趣的:(uvalive)