This commit is contained in:
Zengtudor 2024-09-17 20:04:21 +08:00
parent cf2b7c528a
commit 3fb5c48ee5
3 changed files with 99 additions and 2 deletions

View File

@ -1,4 +1,5 @@
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;

93
20240917/P1991/P1991.cpp Normal file
View File

@ -0,0 +1,93 @@
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
const int MAX_P = 500+5;
struct Dir{
int x,y;
};
struct Edge{
int s,e;
double dis;
bool operator<(const Edge that)const {
return this->dis < that.dis;
}
}edges[MAX_P*MAX_P];
int s,p;
Dir dirs[MAX_P];
decltype(Edge::dis) square(const decltype(Edge::dis) &n){
return n*n;
}
int check_sets[MAX_P];
int find_set(const int n){
if(check_sets[n]==n){
return n;
}else{
check_sets[n] = find_set(check_sets[n]);
}
return check_sets[n];
}
void merge_set(const int a,const int b){
check_sets[find_set(a)] = check_sets[find_set(b)];
}
int main(){
std::cin.sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);
std::cin>>s>>p;
for(int i=1;i<=p;i++){
check_sets[i]=i;
}
for(int i=1;i<=p;i++){
std::cin>>dirs[i].x>>dirs[i].y;
}
int flag = -1;
for(int i=1;i<=p;i++){
for(int j=i+1;j<=p;j++){
flag++;
edges[flag].e=i,edges[flag].s=j,edges[flag].dis=std::sqrt(square(dirs[i].x-dirs[j].x)+square(dirs[i].y-dirs[j].y));
}
}
std::sort(edges,edges+flag+1);
decltype(Edge::dis) ans{0};
// #define NV(v)std::cout<<#v<<" : "<<(v)<<"\n";
#define NV(v)
int cnt{0};
for(int i=0;i<flag;i++){
NV(find_set(edges[i].e));
NV(find_set(edges[i].s));
if(find_set(edges[i].e)!=find_set(edges[i].s)){
NV(edges[i].dis)
merge_set(edges[i].e,edges[i].s);
// std::cout<<"merge "<<edges[i].e<<" "<<edges[i].s<<"\n";
ans=edges[i].dis;
cnt++;
if(cnt>=p-s){
std::cout<<std::fixed<<std::setprecision(2)<<ans<<"\n";
return 0;
}
}
}
}

View File

@ -7,7 +7,7 @@ end
if is_mode("release") and (is_plat("linux")or is_plat("mingw")) then
add_cxxflags("-march=native")
end
set_languages("c++latest")
set_languages("c++23")
set_warnings("all")
target("P1158")
@ -61,3 +61,6 @@ target("oj1808")
target("matchStr")
add_files("20240915/matchStr/*.cpp")
target("P1991")
add_files("20240917/P1991/P1991.cpp")