Beispiel #1
0
int main()
{
    ifstream f("retea2.in");
    ofstream g("retea2.out");
    f>>n>>m;
    for(int i=1; i<=n; ++i) f>>p[i].x>>p[i].y;
    int bi;
    for(int i=1;i<=m; ++i) {
        f>>p[i+n].x>>p[i+n].y;
        dmin[i]=INF;
        for(int j=1; j<=n; ++j) dmin[i]=min(dmin[i],dist(p[j],p[i+n]));
        if(bd>dmin[i]) {
            bd=dmin[i];
            bi=i;
        }
        b.insert(i);
    }
    for(;b.size();) {
        b.erase(b.find(bi));
        cst+=bd;
        bd=INF;
        for(is i=b.begin(); i!=b.end(); ++i) dmin[*i]=min(dmin[*i],dist(p[bi+n],p[*i+n]));
        for(is i=b.begin(); i!=b.end(); ++i) if(bd>dmin[*i]) {
            bd=dmin[*i];
            bi=*i;
        }
    }
    g<<fixed<<setprecision(6)<<cst;
    cout<<fixed<<setprecision(6)<<cst;
    return 0;
}
Beispiel #2
0
 void remove_sets_not_containing(const uint x){
   if(fix.find(x) == fix.end()){ // if x in fix, then x is already in all sets
     if(variable.find(x) != variable.end()){ // if x is optional, then make it madatory
       fix.insert(x);
       variable.erase(x);
     } else clear(); // if x is not in any set, then remove all sets
   }
 }
Beispiel #3
0
 // remove all sets that (do not) contain an item
 void remove_sets_containing(const uint x){
   if(fix.find(x) == fix.end()) // if x not in fix, then just remove all occurances of it from variable
     variable.erase(x);
   else clear(); // if x in fix, then all sets contain x, so clear the compact_set
 }
Beispiel #4
0
 // check containment of (lists of) items in all/some of the sets
 bool all_sets_contain(const uint x) const{
   return fix.find(x) != fix.end();
 }
Beispiel #5
0
 bool some_sets_contain(const uint x) const{
   return (fix.find(x) != fix.end()) || (variable.find(x) != variable.end());
 }
Beispiel #6
0
 // add or remove a (list of) items from all sets
 inline void add_to_all(const uint x){
   fix.insert(x);
 }
Beispiel #7
0
 inline void remove_all_from_all(const uint x){
   fix.erase(x);
   variable.erase(x);
 }
Beispiel #8
0
 // return whether there are some elements that are fix
 inline bool has_no_fixed_elements() const {
   return fix.empty();
 }
Beispiel #9
0
 // multiply all sets in the list with all subsets of X (add all subsets to all sets in the list)
 inline void multiply_with_subsets(const list<uint>& X){
   for(uint x: X) variable.insert(x);
 }
Beispiel #10
0
 // multiply all sets in the list with one set X (add this set to all sets in the list)
 inline void multiply_with_set(const list<uint>& X){
   for(uint x: X) fix.insert(x);
 }
Beispiel #11
0
 // clear
 inline void clear(){
   fix.clear();
   variable.clear();
 }
Beispiel #12
0
 // return whether the list contains no element
 bool empty() const{
   return fix.empty() && variable.empty();
 }