[JSOI2016] 炸弹攻击1

前言

这题很离谱。

题目

洛谷

DarkBZOJ

讲解

我退火调参调一下午最多都只有 90pts,爬山一下就过了,我也不知道谁是sb。

好消息是我退火在洛谷上过了,坏消息是在DarkBZOJ上嗝屁了。

代码

在洛谷上过了的退火。
//12252024832524
#include <bits/stdc++.h>
#define TT template<typename T>
using namespace std; 

typedef long long LL;
const int MAXN = 15;
const int MAXM = 1005;
const double eps = 1e-7;
int n,m,R,ans;

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
TT void Put1(T x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}

mt19937 rd(20050525);
uniform_real_distribution<> realnum(0,1);
LL Rand(LL l,LL r){return rd()%(r-l+1)+l;}

struct architecture{
	int x,y,r;
}a[MAXN];
struct enemy{
	int x,y;
}e[MAXM];
double nowx,nowy;
double sq(double x){return x * x;}
int calc(double x,double y){
	double MIN = R;
	for(int i = 1;i <= n;++ i) MIN = Min(MIN,sqrt(sq(a[i].x-x)+sq(a[i].y-y))-a[i].r);
	if(MIN < 0) return -1;
	int ret = 0;
	for(int i = 1;i <= m;++ i)
		if(sqrt(sq(e[i].x-x)+sq(e[i].y-y)) <= MIN) ++ret;
	return ret;
}

int main()
{
// 	freopen("4852.in","r",stdin);
// 	freopen("4852.out","w",stdout);
	n = Read(); m = Read(); R = Read();
	for(int i = 1;i <= n;++ i) a[i].x = Read(),a[i].y = Read(),a[i].r = Read();
	for(int i = 1;i <= m;++ i) e[i].x = Read(),e[i].y = Read(),nowx += e[i].x,nowy += e[i].y; 
	ans = calc(nowx/=m,nowy/=m);
	uniform_real_distribution<> gan(-R*2,R*2);
	while(1.0 * clock() / CLOCKS_PER_SEC < 0.90)
		for(double T = 2;T > eps;T *= 0.997){
			double nx = nowx + gan(rd) * T,ny = nowy + gan(rd) * T;
			int val = calc(nx,ny);
			if(val > ans) ans = val,nowx = nx,nowy = ny;
			else if(exp(-(ans-val)/T/0.067) >= realnum(rd)) nowx = nx,nowy = ny;
		}
	Put(ans,'\n');
	return 0;
}
两个地方都过了的爬山。
//12252024832524
#include <bits/stdc++.h>
#define TT template<typename T>
using namespace std; 

typedef long long LL;
const int MAXN = 15;
const int MAXM = 1005;
const double eps = 1e-10;
int n,m,R,ans;

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
TT void Put1(T x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}

mt19937 rd(20041015);
uniform_real_distribution<> realnum(0,1);
LL Rand(LL l,LL r){return rd()%(r-l+1)+l;}

struct architecture{
	int x,y,r;
}a[MAXN];
struct enemy{
	int x,y;
}e[MAXM];
double nowx,nowy;
double sq(double x){return x * x;}
int calc(double x,double y){
	double MIN = R;
	for(int i = 1;i <= n;++ i) MIN = Min(MIN,sqrt(sq(a[i].x-x)+sq(a[i].y-y))-a[i].r);
	if(MIN < 0) return -1;
	int ret = 0;
	for(int i = 1;i <= m;++ i)
		if(sqrt(sq(e[i].x-x)+sq(e[i].y-y)) <= MIN) ++ret;
	return ret;
}

int main()
{
//	freopen("4852.in","r",stdin);
//	freopen("4852.out","w",stdout);
	n = Read(); m = Read(); R = Read();
	for(int i = 1;i <= n;++ i) a[i].x = Read(),a[i].y = Read(),a[i].r = Read();
	for(int i = 1;i <= m;++ i) e[i].x = Read(),e[i].y = Read(),nowx += e[i].x,nowy += e[i].y; 
	ans = calc(nowx/=m,nowy/=m);
	uniform_real_distribution<> gan(-R*2,R*2);
	while(1.0 * clock() / CLOCKS_PER_SEC < 0.9)
		for(double T = 2900;T > eps;T *= 0.9973){
			double nx = nowx + Rand(-(1<<14),1<<14) * T,ny = nowy + Rand(-(1<<14),1<<14) * T;
			int val = calc(nx,ny);
			if(val > ans) ans = val,nowx = nx,nowy = ny;
//			else if(exp(-(ans-val)/T/0.067) >= realnum(rd)) nowx = nx,nowy = ny;
		}
	Put(ans,'\n');
	return 0;
}
posted @ 2022-02-21 20:25  皮皮刘  阅读(53)  评论(0编辑  收藏  举报