This commit is contained in:
Zengtudor 2024-10-10 19:32:01 +08:00
parent 576b97f16d
commit 569e030b48

View File

@ -6,7 +6,6 @@
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <string> #include <string>
#include <bitset>
#define NV(v)#v<<" : "<<(v) #define NV(v)#v<<" : "<<(v)
#ifdef NDEBUG #ifdef NDEBUG
@ -25,8 +24,8 @@ Point points[max_n];
std::string s; std::string s;
double mtx_len[max_n][max_n]; double mtx_len[max_n][max_n];
double max_len[max_n]; double max_len[max_n];
const double double_inf = std::numeric_limits<double>::max(), double_min = std::numeric_limits<double>::min(); const double double_max = std::numeric_limits<double>::max(), double_min = std::numeric_limits<double>::min();
double min_ans = std::numeric_limits<double>::max(); double min_ans {double_max}, default_ans{double_min};
double len(const Point &p1, const Point &p2){ double len(const Point &p1, const Point &p2){
return std::sqrt( return std::sqrt(
@ -51,8 +50,9 @@ int main(){
} }
if(s[j-1]=='1'){ if(s[j-1]=='1'){
mtx_len[i][j] = len(points[i],points[j]); mtx_len[i][j] = len(points[i],points[j]);
default_ans = std::max(default_ans,mtx_len[i][j]);
}else{ }else{
mtx_len[i][j] = double_inf; mtx_len[i][j] = double_max;
} }
} }
} }
@ -60,7 +60,7 @@ int main(){
for(ull i=1;i<=n;i++){ for(ull i=1;i<=n;i++){
for(ull j=1;j<=n;j++){ for(ull j=1;j<=n;j++){
double new_len; double new_len;
if(mtx_len[i][k]!=double_inf && mtx_len[k][j]!=double_inf){ if(mtx_len[i][k]!=double_max && mtx_len[k][j]!=double_max){
new_len = mtx_len[i][k]+mtx_len[k][j]; new_len = mtx_len[i][k]+mtx_len[k][j];
}else{ }else{
continue; continue;
@ -74,10 +74,10 @@ int main(){
} }
for(ull i=1;i<=n;i++){ for(ull i=1;i<=n;i++){
max_len[i]=double_inf; max_len[i]=double_max;
for(ull j=1;j<=n;j++){ for(ull j=1;j<=n;j++){
if(mtx_len[i][j]==double_inf)continue; if(mtx_len[i][j]==double_max)continue;
max_len[i] = std::max(mtx_len[i][j],(max_len[i]==double_inf?double_min:max_len[i])); max_len[i] = std::max(mtx_len[i][j],(max_len[i]==double_max?double_min:max_len[i]));
} }
} }
DEBUG( DEBUG(
@ -85,7 +85,7 @@ int main(){
) )
for(ull i=1;i<=n;i++){ for(ull i=1;i<=n;i++){
for(ull j=i+1;j<=n;j++){ for(ull j=i+1;j<=n;j++){
if(mtx_len[i][j]==double_inf){ if(mtx_len[i][j]==double_max){
DEBUG( DEBUG(
std::cout<<NV(i)<<'\n'<<NV(j)<<'\n'<<NV(max_len[i])<<'\n'<<NV(max_len[j])<<'\n' std::cout<<NV(i)<<'\n'<<NV(j)<<'\n'<<NV(max_len[i])<<'\n'<<NV(max_len[j])<<'\n'
<<NV(len(points[i], points[j]))<<'\n'<<NV(max_len[i]+ len(points[i], points[j]) + max_len[j])<<'\n'; <<NV(len(points[i], points[j]))<<'\n'<<NV(max_len[i]+ len(points[i], points[j]) + max_len[j])<<'\n';
@ -99,5 +99,5 @@ int main(){
} }
} }
std::cout<<std::fixed<<std::setprecision(6)<<min_ans<<'\n'; std::cout<<std::fixed<<std::setprecision(6)<<std::max(min_ans, default_ans)<<'\n';
} }