update
This commit is contained in:
parent
9797c78137
commit
f9e10f2f9a
83
src/P1522/P1522.cpp
Normal file
83
src/P1522/P1522.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define NV(v)#v<<" : "<<(v)
|
||||||
|
|
||||||
|
using ull = unsigned long long;
|
||||||
|
const size_t max_n = 150+5;
|
||||||
|
struct Point{
|
||||||
|
ull x,y;
|
||||||
|
};
|
||||||
|
ull n;
|
||||||
|
Point points[max_n];
|
||||||
|
std::string s;
|
||||||
|
double mtx_len[max_n][max_n];
|
||||||
|
double max_len[max_n];
|
||||||
|
const double double_inf = std::numeric_limits<double>::max(), double_min = std::numeric_limits<double>::min();
|
||||||
|
double min_ans = std::numeric_limits<double>::max();
|
||||||
|
|
||||||
|
double len(const Point &p1, const Point &p2){
|
||||||
|
return std::sqrt(
|
||||||
|
std::pow((double)p1.x-(double)p2.x, (double)2)+
|
||||||
|
std::pow((double)p1.y-(double)p2.y,(double)2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
// std::cout<<INF<<'\n';
|
||||||
|
std::cin>>n;
|
||||||
|
|
||||||
|
for(ull i = 1;i<=n;i++){
|
||||||
|
std::cin>>points[i].x>>points[i].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ull i=1;i<=n;i++){
|
||||||
|
std::cin>>s;
|
||||||
|
for(ull j=1;j<=n;j++){
|
||||||
|
if(s[j-1]=='1'){
|
||||||
|
mtx_len[i][j] = len(points[i],points[j]);
|
||||||
|
}else{
|
||||||
|
mtx_len[i][j] = double_inf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(ull k=1;k<=n;k++){
|
||||||
|
for(ull i=1;i<=n;i++){
|
||||||
|
for(ull j=1;j<=n;j++){
|
||||||
|
double new_len;
|
||||||
|
if(mtx_len[i][k]!=double_inf && mtx_len[k][j]!=double_inf){
|
||||||
|
new_len = mtx_len[i][k]+mtx_len[k][j];
|
||||||
|
}else{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(new_len<mtx_len[i][j]){
|
||||||
|
mtx_len[i][j] = new_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ull i=1;i<=n;i++){
|
||||||
|
max_len[i]=double_inf;
|
||||||
|
for(ull j=1;j<=n;j++){
|
||||||
|
if(mtx_len[i][j]==double_inf)continue;
|
||||||
|
max_len[i] = std::max(mtx_len[i][j],(max_len[i]==double_inf?double_min:max_len[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout<<NV(min_ans)<<"\n---start\n";
|
||||||
|
for(ull i=1;i<=n;i++){
|
||||||
|
for(ull j=i+1;j<=n;j++){
|
||||||
|
if(mtx_len[i][j]==double_inf){
|
||||||
|
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';
|
||||||
|
min_ans = std::min(max_len[i]+ len(points[i], points[j]) +max_len[j],min_ans);
|
||||||
|
std::cout<<NV(min_ans)<<'\n';
|
||||||
|
std::cout<<"---\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<min_ans<<'\n';
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user