求助此代码为什么开O2会RE
查看原帖
求助此代码为什么开O2会RE
335264
Liooooo楼主2022/8/30 14:48

RT

#include <bits/stdc++.h>
using namespace std;
		
//#define int long long
		
inline int read()
{
	int a = 0, b = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') b = -1; c = getchar(); }
	while(c <= '9' && c >= '0') { a = a * 10 + c - 48; c = getchar(); }
	return a * b;
}
		
inline void write(int n)
{
	if(n > 9) write(n / 10);
	putchar(n % 10 + 48);
}
		
struct node
{
	double x, y, r;
} e[50];
		
struct NODE
{
	double x, y;
} js[2020];
		
double n, m, r;
double ax, ay, ans, sumx, sumy;
double t, dt = 0.9972, t0 = 1e-14;
		
double qur(double x, double y, double xx, double yy)
{
	return sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy));
}
		
double calc(double x, double y)
{
	double res = 0, d = r;
	for(int i = 1 ; i <= n ; ++ i)
	{
		d = min(d, qur(x, y, e[i].x, e[i].y) - e[i].r);
	}
	for(int i = 1 ; i <= m ; ++ i)
	{
		if(qur(x, y, js[i].x, js[i].y) <= d) res ++;
	}
	return res;
}
		
void firedown()
{
	double ansx = ax, ansy = ay;
	t = 3000;
	while(t > t0)
	{
		double X = ansx + ((rand() << 1) - RAND_MAX) * t;
		double Y = ansy + ((rand() << 1) - RAND_MAX) * t;
		double delta = calc(X, Y) - ans;
		if(delta > 0)
		{
			ax = X; ay = Y;
			ans = calc(X, Y);
		}else if(exp(-delta / t) * RAND_MAX < rand())
		{
			ax = X; ay = Y;
		}
		t *= dt;
	}
}
		
void solve()
{
	ax = sumx / m; ay = sumy / m;
	for(int i = 1 ; i <= 6 ; ++ i) firedown();
	//while((double) clock() / CLOCKS_PER_SEC <= 0.8) firedown();
}
		
int main()
{
	//ios::sync_with_stdio(false);
	srand(time(0));
	scanf("%lf%lf%lf", &n, &m, &r);
	for(int i = 1 ; i <= n ; ++ i)
	{
		scanf("%lf%lf%lf", &e[i].x, &e[i].y, &e[i].r);
	}
	for(int i = 1 ; i <= m ; ++ i)
	{
		scanf("%lf%lf", &js[i].x, &js[i].y);
		sumx += e[i].x;
		sumy += e[i].y;
	}
	solve();
	printf("%.0lf", ans);
	return 0;
}
2022/8/30 14:48
加载中...