コード例 #1
0
void VersionVector::keyUnion( set_t& keys, const VersionVector& other ) const
{
    for( auto& pair : *this )
        keys.insert( pair.first );
    for( auto& pair : other )
        keys.insert( pair.first );
}
コード例 #2
0
ファイル: O.cpp プロジェクト: alxsoares/OI
	void init() {
		event.clear();
		box.clear();
		seq.clear();
		memset(dgr, 0, sizeof(int) * n_stuff);
		memset(adj, 0, sizeof(adj));
	}
コード例 #3
0
ファイル: O.cpp プロジェクト: alxsoares/OI
	void build_graph() {
		for ( int i = 0; i < n_stuff; i ++ ) {
			event.push_back(Event(stuff[i].x1, i, ENTER));
			event.push_back(Event(stuff[i].x2, i, LEAVE));
		}
		sort(event.begin(), event.end(), cmp_event);
		axis = 0;
		for ( int i = 0; i < 2 * n_stuff; i ++ ) {
			int st = i;
			while ( i + 1 < 2 * n_stuff &&
					event[i + 1].x == event[i].x )
				i ++;
			for ( int k = st; k <= i; k ++ ) {
				int t = event[k].id;
				if ( event[k].typ == ENTER )
					stuff[t].l = axis;
				else
					stuff[t].r = axis;
			}
			axis ++;
		}

		for ( vector<Event>::iterator ev = event.begin();
				ev != event.end(); ev ++ ) {
			if ( ev->typ == ENTER ) {
				pair<set_t::iterator, bool> res = box.insert(ev->id);
				set_t::iterator it = res.first;
				it ++;
				if ( it != box.end() ) {
					dgr[*it] ++;
					adj[ev->id].push_back(*it);
				}
				it --;
				if ( it != box.begin() ) {
					it --;		
					dgr[ev->id] ++;
					adj[*it].push_back(ev->id);
				}
			} else {
				set_t::iterator it = box.lower_bound(ev->id);
				box.erase(it);
			}
		}
	}
コード例 #4
0
boost::optional<std::vector<pos>> random_walk_impl(
    const State &st, set_t &memo, std::mt19937 &mt, uint64_t &count) {
  if (st.bd.is_goal()) return std::vector<pos>();
  if (count % 10000 == 0) std::cerr << count << std::endl;
  ++count;
  memo.insert(st.bd.units);
  auto nexts = next_states(st);
  std::vector<std::tuple<State, pos>> coodinates;
  for (auto &next : nexts)
    if (memo.count(std::get<0>(next).bd.units) == 0)
      coodinates.push_back(next);
  if (coodinates.empty()) return boost::none;
  std::shuffle(std::begin(coodinates), std::end(coodinates), mt);
  for (auto next : coodinates) {
    if (auto opt_res = random_walk_impl(std::get<0>(next), memo, mt, count)) {
      opt_res->push_back(std::get<1>(next));
      return opt_res;
    }
  }
  return boost::none;
} 
コード例 #5
0
ファイル: quadtree.cpp プロジェクト: rikshot/sandbox
 void quadtree::node::find(sandbox::rectangle const & rectangle, set_t & objects) const {
   if(rectangle.overlaps(rectangle_)) {
     for(auto object_with_bounding_box : objects_) {
       auto const & object(object_with_bounding_box.first);
       auto const & bounding_box(object_with_bounding_box.second);
       if(rectangle.overlaps(bounding_box)) {
         objects.emplace(object);
       }
     }
     if(nw_) nw_->find(rectangle, objects);
     if (ne_) ne_->find(rectangle, objects);
     if (se_) se_->find(rectangle, objects);
     if (sw_) sw_->find(rectangle, objects);
   }
 }
コード例 #6
0
ファイル: O_cp.cpp プロジェクト: alxsoares/OI
	void solve2() {
		typedef set<int, cmp_height> set_t;
		static vector<Event> event;
		static set_t box;
		static stack<int> stk;
		static vector<int> seq;
		static int dgr[N_MAX];
		static vector<int> adj[N_MAX];

		for ( int i = 0; i < n_stuff; i ++ ) {
			event.push_back(Event(stuff[i].x1, i, ENTER));
			event.push_back(Event(stuff[i].x2, i, LEAVE));
		}
		sort(event.begin(), event.end(), cmp_event);
		for ( vector<Event>::iterator ev = event.begin();
				ev != event.end(); ev ++ ) {
			if ( ev->typ == ENTER ) {
				pair<set_t::iterator, bool> res = box.insert(ev->id);
				set_t::iterator it = res.first;
				it ++;
				if ( it != box.end() ) {
					dgr[*it] ++;
					adj[ev->id].push_back(*it);
					//fprintf(stderr, "%d->%d\n", ev->id, *it);
				}
				it --;
				if ( it != box.begin() ) {
					it --;		
					dgr[ev->id] ++;
					adj[*it].push_back(ev->id);
					//fprintf(stderr, "%d->%d\n", *it, ev->id);
				}
			} else 
				box.erase(box.lower_bound(ev->id));
		}

		for ( int i = 0; i < n_stuff; i ++ )
			if ( dgr[i] == 0 )
				stk.push(i);
		while ( !stk.empty() ) {
			int u = stk.top(); stk.pop();
			seq.push_back(u);
			for ( vector<int>::iterator it = adj[u].begin();
					it != adj[u].end(); it ++ ) {
				int v = *it;
				dgr[v] --;
				if ( dgr[v] == 0 )
					stk.push(v);
			}
		}

		assert((int)seq.size() == n_stuff);
		for ( int i = 0; i < n_stuff; i ++ )
			printf("%d %d\n", seq[i] + 1, 3);
	}
コード例 #7
0
void make_trees(std::multimap<int,Grid> &root, set_t &s, string file) {
    string sLine = "";
    ifstream data(file.c_str());
    int count = 0;
    while (getline(data, sLine)) {
        if (count < SIZE) {
            string *lineIndex;
            lineIndex = extractIndexString(sLine, 5);
            int hind = (int)atof(lineIndex[4].c_str());
            s.insert(hind);

            Grid grid;
            grid.x = (int)atof(lineIndex[2].c_str());
            grid.y = (int)atof(lineIndex[3].c_str());
            root.insert(std::make_pair(hind,grid));
            count++;
        }
    }
    data.close();
}
コード例 #8
0
ファイル: collection.hpp プロジェクト: Aligorith/blender
 set_insert_iterator &
 operator=(typename set_t::const_reference value) {
   set->insert(value);
   return *this;
 }
コード例 #9
0
ファイル: Lang.cpp プロジェクト: JohnsonRanger/cerl
	bool TPL_CALL operator()(const ValueT& val) const {
		key_t k(val.begin(), val.end());
		return m_set.find(k) == m_set.end();
	}
コード例 #10
0
ファイル: Lang.cpp プロジェクト: JohnsonRanger/cerl
	IsNotKeywords(const CharT* keywords[], size_t n) {
		while (n--) {
			m_set.insert(keywords[n]);
		}
	}
コード例 #11
0
ファイル: O.cpp プロジェクト: alxsoares/OI
namespace solve {
#define LEAVE 0
#define ENTER 1
	struct Event {
		int x, id, typ;
		Event(int _x, int _id, int _typ):
			x(_x), id(_id), typ(_typ){}
	};

	bool cmp_event(const Event &e1, const Event &e2) {
		//leave first
		return e1.x < e2.x || (e1.x == e2.x && e1.typ < e2.typ);
	}


	struct cmp_height {
		bool operator()(int i, int j) const{
			int x = max(stuff[i].x1, stuff[j].x1);
			double t1 = (double)stuff[j].b * (stuff[i].c + stuff[i].a * x),
			   t2 = (double)stuff[i].b * (stuff[j].c + stuff[j].a * x);
			return t1 > t2;
		}
	};
	typedef set<int, cmp_height> set_t;
	vector<Event> event;
	set_t box;
	stack<int> stk;
	vector<int> seq;
	int val[N_MAX];
	int dgr[N_MAX];
	vector<int> adj[N_MAX];
	int axis;

	void init() {
		event.clear();
		box.clear();
		seq.clear();
		memset(dgr, 0, sizeof(int) * n_stuff);
		memset(adj, 0, sizeof(adj));
	}

	void build_graph() {
		for ( int i = 0; i < n_stuff; i ++ ) {
			event.push_back(Event(stuff[i].x1, i, ENTER));
			event.push_back(Event(stuff[i].x2, i, LEAVE));
		}
		sort(event.begin(), event.end(), cmp_event);
		axis = 0;
		for ( int i = 0; i < 2 * n_stuff; i ++ ) {
			int st = i;
			while ( i + 1 < 2 * n_stuff &&
					event[i + 1].x == event[i].x )
				i ++;
			for ( int k = st; k <= i; k ++ ) {
				int t = event[k].id;
				if ( event[k].typ == ENTER )
					stuff[t].l = axis;
				else
					stuff[t].r = axis;
			}
			axis ++;
		}

		for ( vector<Event>::iterator ev = event.begin();
				ev != event.end(); ev ++ ) {
			if ( ev->typ == ENTER ) {
				pair<set_t::iterator, bool> res = box.insert(ev->id);
				set_t::iterator it = res.first;
				it ++;
				if ( it != box.end() ) {
					dgr[*it] ++;
					adj[ev->id].push_back(*it);
				}
				it --;
				if ( it != box.begin() ) {
					it --;		
					dgr[ev->id] ++;
					adj[*it].push_back(ev->id);
				}
			} else {
				set_t::iterator it = box.lower_bound(ev->id);
				box.erase(it);
			}
		}
	}
	void topsort() {
		for ( int i = 0; i < n_stuff; i ++ )
			if ( dgr[i] == 0 )
				stk.push(i);
		while ( !stk.empty() ) {
			int u = stk.top(); stk.pop();
			seq.push_back(u);
			for ( vector<int>::iterator it = adj[u].begin();
					it != adj[u].end(); it ++ ) {
				int v = *it;
				dgr[v] --;
				if ( dgr[v] == 0 )
					stk.push(v);
			}
		}

		for ( int i = 0; i < n_stuff; i ++ )
			val[seq[i]] = i;
	}

	int main() {
		init();
		build_graph();
		topsort();
		sgt::build(0, axis - 1);
		int res = inf;
		for ( int i = n_stuff - 1; i >= 0; i -- ) {
			int t = cmd[i].des;
			if ( cmd[i].on ) {
				int l = stuff[t].l, r = stuff[t].r - 1;
				if ( l <= r ) {
					int tmp = sgt::ask_min(l, r);
					if ( tmp < val[t] )
						res = i;
				}
			}
			if ( stuff[t].r > stuff[t].l )
				sgt::cover(stuff[t].l, stuff[t].r - 1, val[t]);
		}
		return res;
	}
}