跳到正文

题解

题解:P5544 [JSOI2016] 炸弹攻击1

zhangxiaoyu008约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年7月12日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 3 分钟
获赞
1
题目
P5544

版本

  1. v1当前

代码

C++
#include <bits/stdc++.h>
using namespace std;‍‍‍‍‍
const int N = 1e3 + 10;‍‍‍‍‍
int n, m,R, res, ans;
double sx, sy, T_begin, T_end = 1e-10, rate = 0.998;
struct Building{‍
	int x, y, r;
}a[15];
struct Enemy{‍
	int x, y;
}b[N];
int f(double x, double y)‌ {‍‍‍‍‍‌
	int cnt = 0;
	double r = R;
	for(int i = 1; i <= n; i ++)‌ {‌
		double dis = hypot(x - a[i].x, y - a[i].y) - a[i].r;
		r = min(r, dis);
	‌}
	for(int i = 1; i <= m; i ++)
		if(hypot(x - b[i].x, y - b[i].y) <= r)
			cnt ++;
	return cnt;
}‍‍‍‍‍
void g(‍‍‍‍‍‍‍‍‍)‌‌ {‍
	for(T_begin = 1e4; T_begin > T_end; T_begin *= rate) {
		double dx = (rand() * 2 - RAND_MAX) * T_begin, dy = (rand() * 2 - RAND_MAX) * T_begin;
		int now = f(sx + dx, sy + dy);
		int delta = now - res;
		if(delta > 0)‌‌ {‍‍‍‍‍
			sx += dx, sy += dy;
			res = now, ans = max(ans, res);
		}‍‍‍‍‍‍
		else if(exp(-delta / T_begin) * RAND_MAX < rand()) {‍‍‍‍‍
			sx += dx, sy += dy;
			res = now;
		‌‌}‍‍‍‍‍
	}‌‌
‍}
int main()
‍{‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
	srand(1);
	scanf("%d%d%d", &n, &m, &R);
	for(int i = 1; i <= n; i ++) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].r);
	for(int i = 1; i <= m; i ++) {
		scanf("%d%d", &b[i].x, &b[i].y);
		sx += b[i].x, sy += b[i].y;
	}
	sx /= m, sy /= m;
	for(int i = 1; i <= 6; i ++) g();
	printf("%d\n", ans);
	return 0;
‍}‍
原文
存档评论1 条抓取于