string minMultiples(int N, vector <int> forbiddenDigits) {
		LL _N = N;
		int f[10] = {0};
		int i;
		for (i = 0; i < (int)forbiddenDigits.size(); ++i) {
			f[forbiddenDigits[i] % 10] = 1;
		}
		IntSet allowed;
		for (i = 0; i < 10; ++i) {
			if (!f[i]) {
				allowed.insert(i);
			}
		}

		const LL Max = 1000000000;
		LL ans = Max;
		IntSet M;
		IIQueue Q;
		IntSet::const_iterator it;
		for (it = allowed.begin(); it != allowed.end(); ++it) {
			Q.push(LLPair(*it, 10));
		}
		while (!Q.empty()) {
			LLPair p = Q.front();
			Q.pop();
			LL n = p.first;
			if (n != 0) {
				int r = (int)(n % N);
				if (r == 0) {
					ans = min(ans, n);
					continue;
				} else if (M.find(r) != M.end()) {
					continue;
				} else {
					M.insert(r);
				}
			}
			if (ans < Max) {
				continue;
			}
			for (it = allowed.begin(); it != allowed.end(); ++it) {
				Q.push(LLPair(p.second * *it + n, p.second * 10));
			}
		}

		if (ans < Max) {
			char res[32];
			if (ans <= 99999999) {
				sprintf(res, "%lld", ans);
			} else {
				sprintf(res, "%lld", ans);
				int digits = strlen(res);
				sprintf(res + 3, "...%d(%d digits)", (int)(ans % 1000), digits);
			}
			return res;
		}

		return "IMPOSSIBLE";
	}
Example #2
0
static void Set_Intersect(const IntSet& aset, IntSet& bset)
{
	IntSet tmp;
	tmp.swap(bset);
	std::set_intersection(
			aset.begin(), aset.end(),
			tmp.begin(), tmp.end(),
			std::inserter(bset, bset.begin())); 
}
Example #3
0
void getSmallK(const vector<int>& data, IntSet& s, int k) {
	if (data.size() < k || k < 1)
		return;
	for (int i = 0; i < data.size(); ++i) {
		if (s.size() < k)
			s.insert(data[k]);
		else
			if (data[k] < s.begin()) {
				s.erase(s.begin());
				s.insert(data[k]);
			}
	}
	
}
Example #4
0
 IntSet multiplySet(const IntSet& s, int f)
 {
     IntSet ret;
     for (IntSet::const_iterator it = s.begin(); it != s.end(); ++it)
         ret.insert(*it * f);
     return ret;
 }
Example #5
0
// """ -------------------------------------------------------
//
//  Assignment operator
//    The bits of the other SBV are copied.
//
// """ -------------------------------------------------------
SparseBitVect &SparseBitVect::operator=(const SparseBitVect &other) {
  IntSet *bv = other.dp_bits;
  delete dp_bits;
  d_size = other.getNumBits();
  dp_bits = new IntSet;
  std::copy(bv->begin(), bv->end(), std::inserter(*dp_bits, dp_bits->end()));

  return *this;
}
Example #6
0
	string ableToDivide(int n) {
		n *= 2;
		IntSet::const_iterator it;
		for (it = prime.begin(); it != prime.end(); ++it) {
			int x = n - *it;
			if (x < 2) {
				break;
			}
			if (prime.find(x) != prime.end()) {
				return "YES";
			}
		}
		return "NO";
	}
Example #7
0
	int getFortunate(vector <int> a, vector <int> b, vector <int> c) {
		IntSet ab;
		IntSet Z;
		VI::const_iterator ia, ib, ic;
		for (ia = a.begin(); ia != a.end(); ++ia) {
			for (ib = b.begin(); ib != b.end(); ++ib) {
				ab.insert(*ia + *ib);
			}
		}
		for (ic = c.begin(); ic != c.end(); ++ic) {
			IntSet::const_iterator s;
			for (s = ab.begin(); s != ab.end(); ++s) {
				Z.insert(*ic + *s);
			}
		}
		int r = 0;
		IntSet::const_iterator z;
		for (z = Z.begin(); z != Z.end(); ++z) {
			if (isFortunate(*z)) {
				++r;
			}
		}
		return r;
	}
Example #8
0
bool IntSet::IsEqual(const IntSet & my_set) const
{
	set<int>::const_iterator it1, it2;
	it1 =begin();
	it2 = my_set.begin();
	while(it1 != end()){
		if(*it1 != *it2)
			return false;
		it1++, it2++;
	}

	if(it2 == my_set.end())
		return true;
	return false;
}
Example #9
0
    int maxCities(int n, vector <int> a, vector <int> b, vector <int> len) {
        if (n <= 2) {
            return n;
        }
        int d[50][50];
        memset(d, 0x3f, sizeof(d));
        for (int i = 0; i < (int)a.size(); ++i) {
            d[a[i]-1][b[i]-1] = len[i];
            d[b[i]-1][a[i]-1] = len[i];
        }

        for (int k = 0; k < n; ++k) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

        int ans = 2;
        for (int i = 0; i < n; ++i) {
            for (int j = i+1; j < n; ++j) {
                int r = d[i][j];
                if (r < 1e6) {
                    IntSet s;
                    s.insert(i);
                    s.insert(j);
                    for (int k = 0; k < n; ++k) {
                        if (i != k && j != k) {
                            IntSet::const_iterator it;
                            for (it = s.begin(); it != s.end(); ++it) {
                                if (d[k][*it] != r) {
                                    break;
                                }
                            }
                            if (it == s.end()) {
                                s.insert(k);
                            }
                        }
                    }
                    ans = max(ans, (int)s.size());
                }
            }
        }

        return ans;
    }
Example #10
0
Graph::Graph(IntSet vSet, adjHash& edges) {

    this->vSet = vSet;

    // Loop throug each vertex
    IntSet::iterator u;
    for(u = vSet.begin(); u != vSet.end(); u++) {
        IntSet& incVertices = edges[*u];

        // Add only those which are in vSet
        IntSet::iterator v;
        for(v = incVertices.begin(); v != incVertices.end(); v++) {
            if (vSet.find(*v) != vSet.end()) {
                this->eSet[*u].insert(*v);
            }
        }
    }

}
inline void DiscrepancyCorrection::
apply_multiplicative(const Variables& vars, RealVector& approx_fns)
{
  for (ISIter it=surrogateFnIndices.begin(); it!=surrogateFnIndices.end(); ++it)
    approx_fns[*it] *= multCorrections[*it].value(vars);
}
Example #12
0
void NoisyCnaEnumerate::collapse(const StlIntVector& mapNewCharToOldChar,
                                 const StlIntVector& mapOldCharToNewChar,
                                 RootedCladisticNoisyAncestryGraph& G)
{
  typedef std::set<IntPair> IntPairSet;
  
  int k = _M.k();
  const auto& intervals = _M.intervals();
  for (const IntSet& interval : intervals)
  {
    IntSet remappedInterval;
    for (int c : interval)
    {
      int cc = mapOldCharToNewChar[c];
      if (cc != -1)
        remappedInterval.insert(cc);
    }
    if (remappedInterval.size() > 1)
    {
      // get the copy states
      IntPairSet XY;
      const StateTree& S = G.S(*remappedInterval.begin());
      for (int i = 0; i < k; ++i)
      {
        if (S.isPresent(i))
        {
          const auto& xyz = _M.stateToTriple(i);
          // skip state 1,1
          if (xyz._x != 1 || xyz._y != 1)
          {
            XY.insert(IntPair(xyz._x, xyz._y));
          }
        }
      }
      
      for (const IntPair& xy : XY)
      {
        assert(xy.first != 1 || xy.second != 1);
        
        // collect all char-state pairs correspond to CNAs
        IntPairSet toCollapse;
        for (int c : remappedInterval)
        {
          const StateTree& S_c = G.S(c);
          for (int i = 0; i < k; ++i)
          {
            if (S_c.isPresent(i) && _M.stateToTriple(i)._x == xy.first && _M.stateToTriple(i)._y == xy.second)
            {
              int pi_i = S_c.parent(i);
              assert(0 <= pi_i && pi_i < k);
              
              if (_M.stateToTriple(pi_i)._x != xy.first || _M.stateToTriple(pi_i)._y != xy.second)
              {
                // we got a CNA state
                toCollapse.insert(IntPair(c, i));
              }
            }
          }
        }
        
        G.collapse(toCollapse);
      }
    }
  }
}