首页 > 其他分享 >Codeforces Beta Round #2 C. Commentator problem

Codeforces Beta Round #2 C. Commentator problem

时间:2022-12-08 18:58:54浏览次数:47  
标签:int double List Beta Add yy xx problem Commentator

题意

二维平面上,给定三个圆的原点和半径,求一个点到三个圆的视角相同。
三个圆心不共线。

思路

用(距离/半径)表示视角大小,用方差表示视角的波动。
用爬山算法从重心开始四个方向爬山。

C#10 .net6代码

List<double> x = new();
List<double> y = new();
List<double> r = new();

for (int i = 0; i < 3; i++)
{
	var line = Console.ReadLine()!.Split(' ');
	x.Add(double.Parse(line[0]));
	y.Add(double.Parse(line[1]));
	r.Add(double.Parse(line[2]));
}

double xx = x.Sum() / 3;
double yy = y.Sum() / 3;

int[] dx = { 0, 0, -1, 1 };
int[] dy = { -1, 1, 0, 0 };

const double eps = 1e-5;
double t = 1;

double Dist(double x1, double y1, double x2, double y2)
{
	return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

double Gao(double xx, double yy, List<double> x, List<double> y, List<double> r)
{
	List<double> a = new();
	for (int i = 0; i < 3; i++)
	{
		a.Add(Dist(xx, yy, x[i], y[i]) / r[i]);
	}
	double av = a.Sum() / 3;
	double res = 0;
	for (int i = 0; i < 3; i++)
	{
		res += (a[i] - av) * (a[i] - av);
	}
	return res / 3;
}

while (t > eps)
{
	double cur = Gao(xx, yy, x, y, r);
	bool f = false;
	for (int i = 0; i < 4; i++)
	{
		if (Gao(xx + dx[i] * t, yy + dy[i] * t, x, y, r) < cur)
		{
			xx = xx + dx[i] * t;
			yy = yy + dy[i] * t;
			f = true;
			break;
		}
	}
	if (!f)
	{
		t *= 0.5;
	}
}
if (Gao(xx, yy, x, y, r) < eps)
{
	Console.WriteLine($"{xx} {yy}");
}

标签:int,double,List,Beta,Add,yy,xx,problem,Commentator
From: https://www.cnblogs.com/luobo67/p/16966965.html

相关文章