Beispiel #1
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 #2
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 #3
0
 bool some_sets_contain(const uint x) const{
   return (fix.find(x) != fix.end()) || (variable.find(x) != variable.end());
 }
Beispiel #4
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 #5
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();
 }