本文整理汇总了C++中unordered_set::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_set::clear方法的具体用法?C++ unordered_set::clear怎么用?C++ unordered_set::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unordered_set
的用法示例。
在下文中一共展示了unordered_set::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int n;
bool blank = false;
while(cin >> n && n)
{
num=0;
if(blank) cout << endl;
blank=true;
configs.clear();
corpus.clear();
in_stack.clear();
ssc_stack.clear();
memset(matr,0,sizeof matr);
memset(dfs_num,-1,sizeof dfs_num);
memset(dfs_low,-1,sizeof dfs_low);
char c1,c2,c3,c4,c5,c6;
for(int i =0; i < n; ++i)
{
cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
if(c1 != c6)matr[c6-'A'][c1-'A'] = 1;
if(c2 != c6)matr[c6-'A'][c2-'A'] = 1;
if(c3 != c6)matr[c6-'A'][c3-'A'] = 1;
if(c4 != c6)matr[c6-'A'][c4-'A'] = 1;
if(c5 != c6)matr[c6-'A'][c5-'A'] = 1;
corpus.insert(c1-'A');
corpus.insert(c2-'A');
corpus.insert(c3-'A');
corpus.insert(c4-'A');
corpus.insert(c5-'A');
corpus.insert(c6-'A');
}
for(const auto& x : corpus)
{
if(dfs_num[x] == -1)
tarjan_ssc(x);
}
sort(configs.begin(),configs.end());
for(int i =0 ; i < configs.size(); ++i)
{
cout << configs[i][0];
for(int q =1; q < configs[i].length(); ++q)
{
cout << " " << configs[i][q];
}
cout << endl;
}
}
return 0;
}
示例2: main
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int TC; cin >> TC;
for(int tc = 1; tc <= TC; ++tc){
clean();
cin >> n;
//fills graph
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
int temp; cin >> temp;
v[i][j] = temp;
}
}
visited.clear();
//looks which nodes are reachable from 0
dfs(0, -1);
unordered_set<int> cero = visited;
for(auto &a: cero){
dom[0][a] = 1;
}
//runs dfs on graph ignoring node i and sees which nodes are no longer reachable
for(int i = 1; i < n; ++i){
visited.clear();
dfs(0, i);
for(auto &a: cero){
if(!visited.count(a)){
dom[i][a] = 1;
}
}
}
//outputs dominating table
cout << "Case " << tc << ":\n+";
for(int j = 0; j < (n*2)-1; ++j){
cout << "-";
}
cout << "+\n";
for(int i = 0; i < n; ++i){
cout << "|";
for(int j = 0; j < n; ++j){
cout << ((dom[i][j])? "Y": "N") << "|";
}
cout << "\n+";
for(int j = 0; j < (n*2)-1; ++j){
cout << "-";
}
cout << "+\n";
}
}
return 0;
}
示例3: main
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string word, b;
getline(cin, word);
while(word != ""){
for(int i = 0; i < 17; ++i){
lengths[i].clear();
}
back.clear();
visited.clear();
g.clear();
dic.clear();
dic.insert(word);
lengths[word.size()].push_back(word);
while(getline(cin,word) && word != ""){ //fills dictionary
if(!dic.count(word)){
dic.insert(word);
for(auto &c: lengths[word.size()]){
if(c.size() > word.size()) break;
if(dif1(word, c)){
g[word].push_back(c);
g[c].push_back(word);
}
}
lengths[word.size()].push_back(word);
}
}
//runs test cases
getline(cin, word);
while(word != ""){
reset();
stringstream ss(word);
ss >> word >> b;
if(word == b) cout << word;
else if(bfs(word, b)){
cout << word;
print(b);
}else cout << "No solution.";
getline(cin, word);
cout << "\n" << ((word != "")? "\n": "");
visited.clear();
}
getline(cin, word);
if(word != "") cout << "\n";
}
return 0;
}
示例4: SampleMinibatch
void MMSBModel::SampleMinibatch(unordered_set<VIndex>& vertex_batch,
set<pair<VIndex, VIndex> >& link_batch, const Count batch_size) {
vertex_batch.clear();
for (int i = 0; i < batch_size; ++i) {
while (true) {
// randomly sample a vertex from the map<.,.> vertices_
auto it = vertices_.begin();
uint32 nstep = Context::randUInt64() % vertices_.size();
std::advance(it, nstep);
VIndex v = it->first;
if (vertex_batch.find(v) == vertex_batch.end()) { // to avoid duplicate
vertex_batch.insert(v);
break;
}
}
}
CollectLinks(link_batch, vertex_batch);
for (const auto& link : link_batch) {
vertex_batch.insert(link.first);
vertex_batch.insert(link.second);
}
//LOG(INFO)
// << "iter " << iter_ << ", "
// << vertex_batch.size() << " vertexes, "
// << link_batch.size() << " links";
}
示例5: manageConstructionEvent
static void manageConstructionEvent(color_ostream& out) {
if ( handlers[EventType::CONSTRUCTION].empty() )
return;
unordered_set<df::construction*> constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end());
multimap<Plugin*,EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end());
for ( auto a = constructions.begin(); a != constructions.end(); a++ ) {
df::construction* construction = *a;
if ( constructionsNow.find(construction) != constructionsNow.end() )
continue;
for ( auto b = copy.begin(); b != copy.end(); b++ ) {
EventHandler handle = (*b).second;
handle.eventHandler(out, (void*)construction);
}
}
for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) {
df::construction* construction = *a;
if ( constructions.find(construction) != constructions.end() )
continue;
for ( auto b = copy.begin(); b != copy.end(); b++ ) {
EventHandler handle = (*b).second;
handle.eventHandler(out, (void*)construction);
}
}
constructions.clear();
constructions.insert(constructionsNow.begin(), constructionsNow.end());
}
示例6: findNeighborPoints
void findNeighborPoints(vtkDataSet* data, vtkIdType ptId, unordered_set<vtkIdType>& nbrs, vtkIdList* cellIds, vtkIdTypeArray* neighbors = NULL) {
nbrs.clear();
cellIds->Reset();
data->GetPointCells(ptId, cellIds);
for (size_t k = 0; k < cellIds->GetNumberOfIds(); k++) {
vtkCell* cell = data->GetCell(cellIds->GetId(k));
for (size_t l = 0; l < cell->GetNumberOfEdges(); l++) {
vtkCell* edge = cell->GetEdge(l);
vtkIdType s = edge->GetPointId(0);
vtkIdType e = edge->GetPointId(1);
vtkIdType n = -1;
if (s == ptId) {
n = e;
} else if (e == ptId) {
n = s;
}
if (n > -1) {
if (nbrs.find(n) == nbrs.end()) {
nbrs.insert(n);
if (neighbors != NULL) {
neighbors->SetComponent(ptId, nbrs.size() - 1, n);
}
}
}
}
}
}
示例7: main
int main(int argc, char * argv[])
{
if (argc <= 2) {
printf("usage : mvcas gameid algorithm prejudgesize\n, gameid in 1..100, \n algorithm: \tO for order_id\n");
printf("\tD for degree-decrease\n\tM for modecount\n\tR for random\t");
return 0;
}
int gameid;
sscanf(argv[1],"%d",&gameid);
// printf("%d gameid",gameid);
readgraph(gameid);
memset(degree,0,sizeof(degree));
visitedmaskset.clear();
if (argc>=4) {needprejudge = true; sscanf(argv[3],"%d",&prejudgesize); }
for (int i = 0 ; i < map_n ; i++)
for (int j = 0 ; j < map_n ; j++)
if (graph[i][j]) degree[i]++;
if (argv[2][0] =='O')
dfs((1<<map_n)-1,map_ans,original_order_func,0);
else if (argv[2][0] =='D')
dfs((1<<map_n)-1,map_ans,degree_order_func,0);
else if (argv[2][0] =='M') {
loadmode();
dfs((1<<map_n)-1,map_ans,mode_order_func,0);
}
else if (argv[2][0] =='R')
dfs((1<<map_n)-1,map_ans,random_order_func,0);
if (totcnt>MAXX) printf("tot backtrack count > %d\n",MAXX);
else printf("gid=,%d, btcnt=,%d, method=,%s,prejudgesize=,%d\n",gameid,totcnt,argv[2],prejudgesize);
}
示例8: solve
box random_icp::solve(box b, double const precision ) {
thread_local static unordered_set<shared_ptr<constraint>> used_constraints;
used_constraints.clear();
thread_local static vector<box> solns;
thread_local static vector<box> box_stack;
solns.clear();
box_stack.clear();
box_stack.push_back(b);
do {
DREAL_LOG_INFO << "random_icp::solve - loop"
<< "\t" << "box stack Size = " << box_stack.size();
b = box_stack.back();
box_stack.pop_back();
try {
m_ctc.prune(b, m_config);
auto this_used_constraints = m_ctc.used_constraints();
used_constraints.insert(this_used_constraints.begin(), this_used_constraints.end());
} catch (contractor_exception & e) {
// Do nothing
}
if (!b.is_empty()) {
tuple<int, box, box> splits = b.bisect(precision);
int const i = get<0>(splits);
if (i >= 0) {
box const & first = get<1>(splits);
box const & second = get<2>(splits);
if (random_bool()) {
box_stack.push_back(second);
box_stack.push_back(first);
} else {
box_stack.push_back(first);
box_stack.push_back(second);
}
if (m_config.nra_proof) {
m_config.nra_proof_out << "[branched on "
<< b.get_name(i)
<< "]" << endl;
}
} else {
m_config.nra_found_soln++;
if (m_config.nra_found_soln >= m_config.nra_multiple_soln) {
break;
}
if (m_config.nra_multiple_soln > 1) {
// If --multiple_soln is used
output_solution(b, m_config, m_config.nra_found_soln);
}
solns.push_back(b);
}
}
} while (box_stack.size() > 0);
m_ctc.set_used_constraints(used_constraints);
if (m_config.nra_multiple_soln > 1 && solns.size() > 0) {
return solns.back();
} else {
assert(!b.is_empty() || box_stack.size() == 0);
return b;
}
}
示例9: free_hash
// free hash
void free_hash(unordered_set<Structure*, hash_fncts, hash_eq> &structs)
{
unordered_set<Structure*, hash_fncts, hash_eq>::iterator it;
for (it=structs.begin(); it!=structs.end(); it++) {
//free((*it)->str);
delete *it;
}
structs.clear();
}
示例10: reset
///Reset object
inline void reset() {
filecontents = "";
if ( vpos != NULL ) delete [] vpos;
patterns.clear();
categories.clear();
vcat.clear();
sizeofvpos = 0;
ct = NULL;
}
示例11: buildingHandler
void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event event) {
static bool doOnce = false;
if ( !doOnce ) {
//TODO: put this somewhere else
doOnce = true;
EventHandler buildingHandler(Buildings::updateBuildings, 100);
DFHack::EventManager::registerListener(EventType::BUILDING, buildingHandler, NULL);
//out.print("Registered listeners.\n %d", __LINE__);
}
if ( event == DFHack::SC_WORLD_UNLOADED ) {
lastTick = 0;
lastJobId = -1;
for ( auto i = prevJobs.begin(); i != prevJobs.end(); i++ ) {
Job::deleteJobStruct((*i).second);
}
prevJobs.clear();
tickQueue.clear();
livingUnits.clear();
nextItem = -1;
nextBuilding = -1;
buildings.clear();
constructions.clear();
Buildings::clearBuildings(out);
gameLoaded = false;
nextInvasion = -1;
} else if ( event == DFHack::SC_WORLD_LOADED ) {
uint32_t tick = DFHack::World::ReadCurrentYear()*ticksPerYear
+ DFHack::World::ReadCurrentTick();
multimap<uint32_t,EventHandler> newTickQueue;
for ( auto i = tickQueue.begin(); i != tickQueue.end(); i++ ) {
newTickQueue.insert(pair<uint32_t,EventHandler>(tick + (*i).first, (*i).second));
}
tickQueue.clear();
tickQueue.insert(newTickQueue.begin(), newTickQueue.end());
nextItem = 0;
nextBuilding = 0;
lastTick = 0;
nextInvasion = df::global::ui->invasions.next_id;
gameLoaded = true;
}
}
示例12: main
int main() {
int c = 0;
size_t root, here;
string s, a;
while (true) {
scanf("%zu", &n);
if (!n) break;
getchar();
sccSize.resize(n);
fill(sccSize.begin(), sccSize.end(), 0);
words.clear();
wordMapper.clear();
graph.clear();
revGraph.clear();
selectedWord.clear();
for (size_t i = 0; i < n; i++) {
s.clear();
while ((c = getchar()) != 32 && c != 10) s.push_back(char(c));
root = insertWord(s);
if (c == 10) continue;
s.clear();
while ((c = getchar()) != 10) {
if (c == 32) {
if (s.empty()) continue;
here = insertWord(s);
s.clear();
graph[here].emplace_back(root);
revGraph[root].emplace_back(here);
}
else s.push_back(char(c));
}
if (!s.empty()) {
here = insertWord(s);
graph[here].emplace_back(root);
revGraph[root].emplace_back(here);
}
}
SCC();
sum = 0;
for (size_t i = 0; i < n; i++) if (sccSize[i] > 0) reverseDFS(i);
printf("%zu\n", sum);
for (auto &v : wordMapper) {
if (selectedWord.find(sccId[v.second]) != selectedWord.end()) printf("%s ", v.first.c_str());
}
if (sum) puts("");
}
}
示例13: update
bool Goblin::update( int key )
{
int newx=x,newy=y;
int tx=rand()%10+x-5,ty=rand()%10-5+y;
checked.clear();
findPlayer(tx,ty,currentRoom,player->x,player->y);
start:
newx=x;
newy=y;
if(tx!=x && ty==y)
goto mx;
if(ty!=y && tx==x)
goto my;
if(ty!=y && tx!=x)
if(rand()%2==0)
goto mx;
else goto my;
goto end;
mx:
newx=x-sign(x-tx);
if(moveTo(newx,newy))
return 0;
if((newx!=x || newy!=y) && ty!=y)
{
newx=x;
tx=x;
goto my;
}
goto end;
my:
newy=y-sign(y-ty);
if(moveTo(newx,newy))
return 0;
if((newx!=x || newy!=y) && tx!=x)
{
newy=y;
ty=y;
goto mx;
}
goto end;
end:
if(newx!=x)
{
ty+=rand()%3-1;
goto start;
}
if(newy!=y)
{
tx+=rand()%3-1;
goto start;
}
return 0;
}
示例14: saneTest
void saneTest(unsigned iterations=1) {
// Create index
//cerr << "InitializeIndex()..." << flush;
InitializeIndex();
//cerr << "done." << endl;
// Reset
nextDocId=1;
nextQueryId=1;
activeQueries.clear();
pendingResults.clear();
unsigned limit;
for (unsigned i=0; i<iterations; ++i) {
//cerr << "iteration " << i << endl;
limit=rnd(1+(maxActiveQueries/100),maxActiveQueries);
while (activeQueries.size() < limit)
startQuery();
limit=rnd(1+(maxPendingResults/100),maxPendingResults);
while (pendingResults.size() < limit)
matchDocument();
while (pendingResults.size())
getNextAvailRes();
while (activeQueries.size())
endQuery();
maxActiveQueries*=2;
maxPendingResults*=2;
//cerr << endl;
}
//cerr << "\nDestroyIndex()..." << flush;
// Destroy index
DestroyIndex();
//cerr << "done." << endl;
}
示例15: DFSBT
void DFSBT(int ans_limit) {
for (int i = 0 ; i < map_n; i++) nodeQ[i].clear();
nodeQ[0].push_back(0);
int first;
exceptedmask.clear();
while (first < map_n && !succ_exit) {
for (first = 0 ; first < map_n; first++)
while (!nodeQ[i].empty()) {
//recalc path,
enterDFS(first,ans_limit);
}
}
}