[JSOI2016] 炸弹攻击1
前言
这题很离谱。
题目
讲解
我退火调参调一下午最多都只有 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;
}
分类:
奇技淫巧---爬山/模拟退火
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】