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

· · 题解

代码

#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;
‍}‍