离谱东西

P1337 [JSOI2004] 平衡点 / 吊打XXX

@[tlxjy](/user/482610) 这个还是要看运气的 提供参数: 3000 1e-15 0.997 ``` //Code by Misty-Hazers #include<bits/stdc++.h> using namespace std; const int maxn=114514; int n; int w[maxn]; double ans; struct pos{ double x,y; }p[maxn],o,new0; double f(double x){ return x*x; } double dis(pos a,pos b){ return sqrt(f(a.x-b.x)+f(a.y-b.y)); } double get_ans(pos o){ double sum=0; for(int i=1;i<=n;i++){ sum+=(dis(p[i],o)*w[i]); } return sum; } void SA(){ double T=3000; while(T>(1e-15)){ new0.x=o.x+(rand()*2-RAND_MAX)*T; new0.y=o.y+(rand()*2-RAND_MAX)*T; double tmp=get_ans(new0); double delta=tmp-ans; if(delta<0){ ans=tmp;o=new0; } if(exp(-delta/T)*RAND_MAX>rand()){ ans=tmp;o=new0; } T*=0.997; } } signed main(){ srand(time(0)); cin>>n; o.x=o.y=0; for(int i=1;i<=n;i++){ cin>>p[i].x>>p[i].y>>w[i]; o.x+=p[i].x; o.y+=p[i].y; } o.x/=n;o.y/=n; ans=get_ans(o); int girl=6; while(girl--) SA(); printf("%.3lf %.3lf\n",o.x,o.y); return 0; } ```
by Misty7 @ 2023-10-14 10:47:10


@[Misty_Hazers](/user/344543) 但是我现在交了六七十遍还是没过/kk
by CEFqwq @ 2023-10-14 10:49:44


@[tlxjy](/user/482610) 给你看看我的qwq https://www.luogu.com.cn/record/list?pid=P1337&user=344543
by Misty7 @ 2023-10-14 10:50:22


(毕竟是乱搞算法)
by Misty7 @ 2023-10-14 10:51:44


什么问题啊/kk
by CEFqwq @ 2023-10-14 10:55:37


100 次了。
by CEFqwq @ 2023-10-14 11:04:51


@[tlxjy](/user/482610)
by Misty7 @ 2023-10-14 11:08:25


补一下我的SA(有个地方有问题) ``` void SA(){ double T=3000; while(T>(1e-15)){ new0.x=o.x+(rand()*2-RAND_MAX)*T; new0.y=o.y+(rand()*2-RAND_MAX)*T; double tmp=get_ans(new0); double delta=tmp-ans; if(delta<0){ ans=tmp;o=new0; } if(exp(-delta/T)*RAND_MAX>rand()){ o=new0; } T*=0.997; } } ```
by Misty7 @ 2023-10-14 11:09:58


@[tlxjy](/user/482610) https://www.luogu.com.cn/record/129247120 过了,比着您的代码改了改参数,加了个卡时函数。
by Aisaka_Taiga @ 2023-10-14 11:16:05


7次/kk
by Aisaka_Taiga @ 2023-10-14 11:17:35


| 下一页