社区讨论
退火wa30遍,qaq
P1337[JSOI2004] 平衡点 / 吊打XXX参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @locf1gej
- 此快照首次捕获于
- 2023/10/30 12:44 2 年前
- 此快照最后确认于
- 2023/11/05 00:22 2 年前
CPP
#include<bits/stdc++.h>
//#define double long double
#define mc 0.996
using namespace std;
int n;
double ansx,ansy,ans;
struct wa{
int x,y,w;
}a[2005];
inline int read()
{
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(; isdigit(c);c=getchar())x=(x<<3)+(x<<1)+c-'0';
return x*f;
}
double hhh(double x,double y)
{
double em,dx,dy;
for(register int i=1;i<=n;i++){
dx=x-a[i].x,dy=y-a[i].y;
em+=(double)(sqrt(dx*dx+dy*dy)*a[i].w);
}
return em;
}
void fire()
{
double ex,ey,ea,de,t=2021;
while(t>1e-15){
ex=ansx+((rand()<<1)-RAND_MAX)*t;
ey=ansy+((rand()<<1)-RAND_MAX)*t;
ea=hhh(ex,ey);
de=ea-ans;
if(de<0){ansx=ex,ansy=ey,ans=ea;}
else if(exp(-de/t)*RAND_MAX>rand()){ansx=ex,ansy=ey;}
t*=mc;
}
}
void sa()
{
fire();fire();fire();
fire();
fire();
}
int main()
{
register int i;
n=read();
//scanf("%d",&n);
srand(time(0));
for(i=1;i<=n;i++){
a[i].x=read(),a[i].y=read(),a[i].w=read();
//scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
ansx+=a[i].x,ansy+=a[i].y;
}
ansx/=n,ansy/=n;
ans=hhh(ansx,ansy);
sa();
printf("%.3lf %.3lf",ansx,ansy);
return 0;
}
(long double用过也没过
求大佬
回复
共 2 条回复,欢迎继续交流。
正在加载回复...