string square_anagram(string s1, string s2) { int len = s1.length(), i; string ret; for (i = 0; i < len; i++) if ((s1[i] >= 'A' && s1[i] <= 'Z')) break; if (i == len) { if (squares.find(s1) != squares.end() && squares.find(s2) != squares.end()) { if (s1 > s2) return s1; return s2; } return ""; } for (char c = '9'; c >= (i == 0 ? '1' : '0'); c--) { char save = s1[i]; if (used.find(c) != used.end()) continue; replace_all(s1, s2, s1[i], c); used.insert(c); if ((ret = square_anagram(s1, s2)) != "") return ret; used.erase(c); replace_all(s1, s2, c, save); } return ""; }
void getNB(HashGraph* G, int v, int distance, hash_set<int>& result, vector<bool>& mark) { assert(distance==1 || distance==2); EdgeMap* p_neighbors=G->getNeighbors(v); EdgeMap::iterator pnb; for (pnb=p_neighbors->begin(); pnb!=p_neighbors->end(); pnb++) { UINT w=pnb->first; if(!mark[w]) result.insert(w); } if(distance==1) return; hash_set<int>::iterator p; vector<int> temp; for(p=result.begin(); p!=result.end(); p++) temp.push_back(*p); int imnb_size=result.size(); //result.clear(); for(int i=0; i<imnb_size; i++) { p_neighbors=G->getNeighbors(temp[i]); for (pnb=p_neighbors->begin(); pnb!=p_neighbors->end(); pnb++) { UINT w=pnb->first; if(!mark[w]) result.insert(w); //automatically handel duplication. } } for(int i=0; i<imnb_size; i++) result.erase(temp[i]); }
void solve() { int op,x; for( f>>N; N; --N ) { f>>op>>x; switch( op ) { case 1 : H.insert(x); break; case 2 : H.erase(x); break; case 3 : g<< ( H.find(x)!=H.end() ) <<"\n"; } } }