Example #1
0
void bfs(string source) {
  visited.insert(source);
  nodes[source].degree = 0;
  queue<string> q;
  q.push(source);
  while(!q.empty()) {
    string next = q.front();
    q.pop();
    vector<string> nextadj = nodes[next].adj;
    for(int i= 0; i < nextadj.size(); i++) {
      if(visited.count(nextadj[i]) == 0) {
	// cout << "writing " << nextadj[i] << " degree" << endl;
	nodes[nextadj[i]].degree = nodes[next].degree+1;
	visited.insert(nextadj[i]);
	q.push(nextadj[i]);
      }
    }
  }
}
Example #2
0
 bool wordBreak(string s, set<string> &dict) {
     int n=s.size();
     if(n==0) return false;
     vector<bool> ref(n+1,false);
     ref[0]=true;
     for(int i=1;i<=n;i++)
     {
         for(int j=0;j<i;j++)
         {
             string str=s.substr(j+1,i-j);
             if(ref[j]&&dict.count(str))
             {
                 ref[i]=true;
                 break;
             }
         }
     }
     return ref[n];
 }
Example #3
0
    void parseReplsetCmdLine(const std::string& cfgString,
                             string& setname,
                             vector<HostAndPort>& seeds,
                             set<HostAndPort>& seedSet ) {
        const char *p = cfgString.c_str();
        const char *slash = strchr(p, '/');
        if( slash )
            setname = string(p, slash-p);
        else
            setname = p;
        uassert(13093, "bad --replSet config string format is: <setname>[/<seedhost1>,<seedhost2>,...]", !setname.empty());

        if( slash == 0 )
            return;

        p = slash + 1;
        while( 1 ) {
            const char *comma = strchr(p, ',');
            if( comma == 0 ) comma = strchr(p,0);
            if( p == comma )
                break;
            {
                HostAndPort m;
                try {
                    m = HostAndPort( string(p, comma-p) );
                }
                catch(...) {
                    uassert(13114, "bad --replSet seed hostname", false);
                }
                uassert(13096, "bad --replSet command line config string - dups?", seedSet.count(m) == 0 );
                seedSet.insert(m);
                //uassert(13101, "can't use localhost in replset host list", !m.isLocalHost());
                if( m.isSelf() ) {
                    LOG(1) << "replSet ignoring seed " << m.toString() << " (=self)" << rsLog;
                }
                else
                    seeds.push_back(m);
                if( *comma == 0 )
                    break;
                p = comma + 1;
            }
        }
    }
Example #4
0
void build(){
  lvl[ 0 ] = 1;
  for( ll i = 1 ; i < N ; i ++ )
    lvl[ i ] = lvl[ i - 1 ] * i;
  S.insert( 1 );
  Q.push( 1 );
  while( Q.size() ){
    ll tmp = Q.front(); Q.pop();
    ll mx = 1000000000000000000ll / tmp;
    for( int i = 2 ; i < N ; i ++ ){
      if( lvl[ i ] > mx ) break;
      ll nxt = tmp * lvl[ i ];
      if( S.count( nxt ) == 0 ){
        S.insert( nxt );
        Q.push( nxt );
      }
    }
  }
}
Example #5
0
void proc() {
  words.clear();
  taken.clear();
  while(true) {
    char in[200];
    char c;
    scanf("%s%c", in, &c);
    words.push_back(string(in));
    if (c == '\n') {
      break;
    }
  }
  char in[500];
  while (true) {
    fgets(in, 500, stdin);
    if (strchr(in, '?')) {
      break;
    }
    char *sound = strchr(in, ' ');
    sound = strchr(sound + 1, ' ') + 1;
    if (strchr(sound, '\n')) {
      *(strchr(sound, '\n')) = 0;
    }
    taken.insert(string(sound));
  }

  int numPrinted = 0;
  for (int i = 0; i < words.size(); i++) {
    if (taken.count(words[i]) == 0) {
      if (numPrinted != 0) {
        printf(" ");
      }
      numPrinted++;
      printf("%s", words[i].c_str());
    }
  }
  printf("\n");
/*
  for (set<string>::iterator i = taken.begin(); i != taken.end(); i++) {
    printf("%s\n", (*i).c_str());
  }
  */
}
void codevs_ai::input(const input_t & a) {
    remaining_time = a.remaining_time;
    assert (a.stage == stage);
    turn = a.turn;
    resource = a.resource;
    for (auto p : a.visible_resources) if (not resource_points.count(p)) resource_found(p);
    enemy_unit_ids.clear();
    for (auto input : a.units) input_unit(true, input);
    for (auto input : a.visible_enemies) input_unit(false, input);
    {
        set<unit_id> corpses;
        for (auto id : friend_unit_ids) if (units[id]->last_updated < turn) corpses.insert(id);
        for (auto id : corpses) friend_unit_died(id);
    }
    if (not enemy_castle_id) for (auto id : enemy_unit_ids) if (units[id]->kind == kind::castle) castle_found(id);
    assert (friend_unit_ids.size() == a.units.size());
    assert (enemy_unit_ids.size() == a.visible_enemies.size());
    assert (resource_points.size() >= a.visible_resources.size());
}
void ConstrainedMateFixingManager::addReads(const vector<OGERead *> & newReads, const set<OGERead *> & modifiedReads) {
	if(!output_module->isNothreads())
        add_read_lock.lock();

    for (vector<OGERead *>::const_iterator newRead =  newReads.begin(); newRead != newReads.end(); newRead++ ) {
        cmfm_read_t r;
        r.read = *newRead;
        r.readWasModified = modifiedReads.count(*newRead) > 0;
        r.canFlush = false;

        if(output_module->isNothreads())
            addReadInternal(r.read, r.readWasModified, r.canFlush);
        else
            addReadQueue.push(r);
    }

	if(!output_module->isNothreads())
        add_read_lock.unlock();
}
Example #8
0
void user_query(set<string>& container) {
	cout << "Please enter a query string: ";
	string q; 
	getline(cin, q);
	if(q.empty()) {
		return;
	}
	else {
		for(unsigned int i=0; i < q.length(); i++) {
			q[i] = tolower(q[i]);
		}
		int contains = container.count(q);
		if(contains == 0) 
			cout << "not in the file" << endl;
		else
			cout << "in the file" << endl;
		user_query(container);
	}
}
Example #9
0
    bool solve(int i, int j, int m, int n, int off, string &word, vector<vector<char> > &board, set<pair<int, int> > &ss) {
        if (off == word.size())
            return true;
        if (i == -1 || i == m || j == -1 || j == n)
            return false;
        pair<int, int> p(i, j);

        if (ss.count(p)) return false;


        if (board[i][j] != word[off])
            return false;

        ss.insert(p);
        return  solve(i - 1, j, m, n, off + 1, word, board, ss) ||
                solve(i + 1, j, m, n, off + 1, word, board, ss) ||
                solve(i, j - 1, m, n, off + 1, word, board, ss) ||
                solve(i, j + 1, m, n, off + 1, word, board, ss) ;
    }
void genOminoes(int x, set<Block>& curr, int left) {
    if(left == 0) {
        Omino om(curr.begin(), curr.end());
        normalizeOmino(om);
        ominoes[x].insert(om);
        return;
    }

    for(sbiterator it = curr.begin(); it != curr.end(); it++) {
        for(int d = 0; d < 4; d++) {
            Block b = make_pair(it->first + dr[d], it->second + dc[d]);
            if(!curr.count(b)) {
                curr.insert(b);
                genOminoes(x, curr, left - 1);
                curr.erase(b);
            }
        }
    }
}
Example #11
0
 void dfs(vector<int>& num, int d, vector<int>& c)
 {
     if(d == num.size())
     {
         p.push_back(c);
         return;
     }
     for(int i=0;i<num.size();i++)
     {
         if(!s.count(i))
         {
             c.push_back(num[i]);
             s.insert(i);
             dfs(num, d+1, c);
             c.pop_back();
             s.erase(i);
         }
     }
 }
Example #12
0
int main() {
  memset(dpb, -1, sizeof dpb);
  memset(dph, -1, sizeof dph);
  dph[0] = 0;
  dpb[0] = 0;
  hs.insert(0);
  bs.insert(0);
  scanf("%d", &h);
  int v;
  while(h--) {
    scanf("%d", &v);
    set<int> hsn = hs;
    for(set<int>::iterator itr = hs.begin(); itr != hs.end(); itr++) {
      hsn.insert(v + *itr);
      dph[v + *itr] = test(dph[v + *itr], dph[*itr] + 1);
    }
    hs = hsn;
  }
  scanf("%d", &b);
  while(b--) {
    scanf("%d", &v);
    set<int> bsn = bs;
    for(set<int>::iterator itr = bs.begin(); itr != bs.end(); itr++) {
      bsn.insert(v + *itr);
      dpb[v + *itr] = test(dpb[v + *itr], dpb[*itr] + 1);
    }
    bs = bsn;
  }
  const int inf = 2000000000;
  int ans = inf;
  for(set<int>::iterator itr = hs.begin(); itr != hs.end(); itr++) {
    if(*itr == 0)
      continue;
    if(bs.count(*itr)) {
      ans = min(ans, dph[*itr] + dpb[*itr]);
    }
  }
  if(ans == inf)
    printf("impossible\n");
  else
    printf("%d\n", ans);
  return 0;
}
Example #13
0
void findMaxSequenceLength()
{
    valueProduced.clear();
    
    countH = 0;
    backtrackH(0);
    
    int length = 0;
    while (valueProduced.count(length + 1) == 1)
        length++;
        
    if (length > maxSequenceLength)
    {
        kValue.clear();
        for (int i = 0; i < kCandidate.size(); i++)
            kValue.push_back(kCandidate[i]);
        maxSequenceLength = length;
    }
}
bool governmentMapper::ideologyIsValid(const governmentMapping& mapping, const set<string>& majorIdeologies, const map<string, HoI4Ideology*>& ideologies) const
{
	if (majorIdeologies.count(mapping.HoI4GovernmentIdeology) > 0)
	{
		auto ideology = ideologies.find(mapping.HoI4GovernmentIdeology);
		if (ideology != ideologies.end())
		{
			for (auto type: ideology->second->getTypes())
			{
				if (mapping.HoI4LeaderIdeology == type)
				{
					return true;
				}
			}
		}
	}

	return false;
}
string get_server_name(const set<deploy_option> &env)
{
	string wmsvc = "192.168.20";

	if (env.count(deploy_option::RELEASE))
	{
		const int servers[] = { 1, 2, 3 };

		for(const int &s : servers)
		{
			cout << s << ": " << wmsvc << "6.10" << s << endl;
		}

		cout << endl;

		string selectedIndex;

		do
		{
			console::clear_line();
			cout << "Select: ";
			selectedIndex = console::read_line();

			console::offset_cursor_position(0, -1);

			for(const int &s : servers)
			{
				if (selectedIndex == to_string(s))
				{
					break;
				}
			}
		} while (none_of(begin(servers), end(servers), [selectedIndex] (const int &s) { return selectedIndex == to_string(s); }));

		wmsvc.append("6.10");
		wmsvc += selectedIndex;
	}
	else
	{
		wmsvc += "4.50";
	}
	return wmsvc;
}
void remove(int i) {
#ifdef DEBUG
    assert (not is_removed[i]);
    assert (removable.count(i));
#endif
    is_removed[i] = true;
    removable.erase(i);
    auto p = cubes[i];
    for (int dx : {-1,0,1}) {
        for (int dy : {-1,0,1}) {
            point<int> q = { p.x + dx, p.y + dy };
            update(q);
        }
    }
    for (int dx : {-2,2}) {
        point<int> q = { p.x + dx, p.y };
        update(q);
    }
}
Example #17
0
bool path_exits() {
  memset(visited, false, sizeof visited);
  queue<int> q;
  q.push(b);
  visited[b] = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < AdjList[cur].size(); i++) {
      int next = AdjList[cur][i].first;
      if (can_use[next] && !visited[next]) {
	if (exits.count(next)) return true;
	visited[next] = true;
	q.push(next);
      }
    }
  }
  return false;
}
Example #18
0
int main()
{
#ifndef ONLINE_JUDGE
    freopen("/Users/HAN/Documents/in.txt","r",stdin);
#endif
    int n;
    cin >> n;
    string father,son;
    for(int i=0;i<n;++i){
        cin >> father >> son;
        Tree[father].push_back(son);
        not_root.insert(son);
        ancestror[father] = "-1";
        ancestror[son] = "-1";
    }

    int m;
    cin >> m;
    string q1,q2;
    for(int i=0;i<m;++i){
        cin >> q1 >> q2;
        Qes[q1].push_back(q2);
        Qes[q2].push_back(q1);
        RQes.push_back(make_pair(q1,q2));
    }

    for(map<string,vector<string> > ::const_iterator iter = Tree.begin();iter != Tree.end();++iter){
        if(not_root.count(iter->first)){
            continue;
        }else {//根结点
            set<string> visited;
            Dfs(iter->first,visited);
        }
    }

    for(size_t i=0;i< m;++i){
        if(lca.find(RQes[i]) != lca.end()){//查询到
            cout << lca[RQes[i]] << endl;
        }else{
            cout << "-1" << endl;
        }
    }
}
Example #19
0
int bfs(Point src, Point dst) {
   queue<Point> Q;
   Q.push(src);
   dist[src] = 0;
   while(!Q.empty()) {
      Point cur = Q.front();
      Q.pop();
      if(cur == dst) return dist[cur];
      for(int dir = 0; dir < 8; ++dir) {
         Point nxt = make_pair(cur.first + di[dir], cur.second + dj[dir]);
         if(P.count(nxt) == 0) continue;
         if(dist.count(nxt) == 0) {
            dist[nxt] = dist[cur] + 1;
            Q.push(nxt);
         }
      }
   }
   return -1;
}
Example #20
0
    virtual void gotObject( const BSONObj& obj ) {
        if (_curns == OPLOG_SENTINEL) { // intentional ptr compare
            if (obj["op"].valuestr()[0] == 'n') // skip no-ops
                return;
            
            // exclude operations that don't meet (timestamp) criteria
            if ( _opmatcher.get() && ! _opmatcher->matches ( obj ) ) {
                _oplogEntrySkips++;
                return;
            }

            string db = obj["ns"].valuestr();
            db = db.substr(0, db.find('.'));

            BSONObj cmd = BSON( "applyOps" << BSON_ARRAY( obj ) );
            BSONObj out;
            conn().runCommand(db, cmd, out);
            _oplogEntryApplies++;

            // wait for ops to propagate to "w" nodes (doesn't warn if w used without replset)
            if ( _w > 1 ) {
                conn().getLastError(db, false, false, _w);
            }
        }
        else if ( endsWith( _curns.c_str() , ".system.indexes" )) {
            createIndex(obj, true);
        }
        else if (_drop && endsWith(_curns.c_str(), ".system.users") && _users.count(obj["user"].String())) {
            // Since system collections can't be dropped, we have to manually
            // replace the contents of the system.users collection
            BSONObj userMatch = BSON("user" << obj["user"].String());
            conn().update(_curns, Query(userMatch), obj);
            _users.erase(obj["user"].String());
        } else {
            conn().insert( _curns , obj );

            // wait for insert to propagate to "w" nodes (doesn't warn if w used without replset)
            if ( _w > 1 ) {
                conn().getLastErrorDetailed(_curdb, false, false, _w);
            }
        }
    }
Example #21
0
File: vsm.cpp Project: bigsmiles/TC
int myParagraphProcessToVSM(string folderPath)
{
	if(!ICTCLAS_Init()) //初始化分词组件。
	{
		printf("Init fails\n");  
		return 0;
	}
	else
	{
		printf("Init ok\n");
	}
	
	ifstream featureDicFile(featureDicPath.c_str());
	string featureWord;
	double featureVal;
	while(featureDicFile>>featureWord>>featureVal)
		featureDic.insert(featureWord);
	ifstream dicFile(myDicPath.c_str());
	string term;
	int id,cnt,df;
	while(dicFile>>term)
	{
		
		dicFile>>id>>cnt;
		for(int i = 0; i < cnt; i++)
		{
			dicFile>>id>>df;
		}
		if(featureDic.count(term))
			IDFDic[term] = df;
	}
	for(map<string,int>::iterator it = IDFDic.begin(); it != IDFDic.end(); it++)
		cout<<it->first<<" "<<it->second<<endl;
   //设置词性标注集(0 计算所二级标注集,1 计算所一级标注集,2 北大二级标注集,3 北大一级标注集)
	ICTCLAS_SetPOSmap(2);

    testICTCLAS_ParagraphProcessToSVM(folderPath,0);//分词用例
	
	ICTCLAS_Exit();	//释放资源退出
	outFile.close();
	return 1;
}
Example #22
0
int main(){
//    freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin>>q;
    n=0;
    for(int i=0; i<q; ++i){
        string s1,s2;
        cin>>s1>>s2;
        if(mm.count(s1)==0){
            mm[s1]=++n;
            old[n]=s1;
        }
        if(mys.count(s2)) continue;
        newh[mm[s1]]=s2;
        mm[s2]=mm[s1];
        mys.insert(s1); mys.insert(s2);
    }
    cout<<n<<endl;
    for(int i=1; i<=n; ++i) cout<<old[i]<<' '<<newh[i]<<endl;
}
    void deduplicateHelper(
        Contact& contact,
        map<string, vector<Contact> >& email2Contacts,
        set<string>& visited,
        vector<string>& group
    ) {
        if(visited.count(contact.name) > 0)
            return;

        visited.insert(contact.name);
        group.push_back(contact.name);

        for(int i = 0; i < contact.emails.size(); i++) {
            string email = contact.emails[i];
            vector<Contact> neighborContacts = email2Contacts[email];
            for(int j = 0; j < neighborContacts.size(); j++) {
                deduplicateHelper(neighborContacts[j], email2Contacts, visited, group);
            }
        }
    }
Example #24
0
int main()
{
   int n;
   while (scanf("%d",&n)!=EOF)
   {
      a.clear();
      for (int i=1;i<=n;i++)
      {
         scanf("%s",s);
         string p=s;
         if (a.count(p))
            a.erase(p);
         else
            a.insert(p);
      }
      printf("%s\n",!a.empty()?"first player":"second player");
   }
   system("pause");
   return(0);
}
Example #25
0
bool exist_camino(){
	memset(visit,0,sizeof(visit));
	queue<int>Q;
	Q.push(ini);
	visit[ini];
	while(!Q.empty()){
		int cur = Q.front();
		Q.pop();
		for(int i=0;i<G[cur].size();i++){
			int next = G[cur][i].to;
			if(can_use[next]&& !visit[next]){
				if(exist.count(next))
					return true;
				visit[next]=true;
				Q.push(next);
			}
		}
	}
	return false;
}
Example #26
0
File: 5071.cpp Project: Rrbsmoy/ACM
void Close(int u)
{
    if(pc.count(u)==0)
    {
        puts("invalid priority.");
        return ;
    }
    pc.erase(u);
    if(alwayson==u) alwayson=-1;
    int pos=HEAD;
    for(pos=HEAD;pos!=TAIL;pos=chat[pos].back)
    {
        if(chat[pos].pro==u) break;
    }
    int bc=chat[pos].back;
    int ft=chat[pos].front;
    chat[bc].front=ft;
    chat[ft].back=bc;
    printf("close %d with %I64d.\n",chat[pos].pro,chat[pos].w);
}
Example #27
0
File: A.cpp Project: nitish1402/OPC
int min_width(const string& x, const set<char>& y) {
  int ret = x.size();
  map<char, int> index;
  set<int> index_set;

  for (int j = 0; j < x.size(); j++) {
    if (y.count(x[j]) > 0) {
      if (index.count(x[j]) > 0)
        index_set.erase(index[x[j]]);
      index_set.insert(j);
      index[x[j]] = j;
      if (index.size() == y.size()) {
        int i = *index_set.begin();
        if (ret > j-i+1)
          ret = j-i+1;
      }
    }
  }
  return ret;
}
Example #28
0
int main(){
    int mx=1000000001;
    s.clear();
    int now=2;
    while(now<mx){
        s.insert(now);
        now=now*2+1;
    }
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        if(s.count(n))
            printf("Bob\n");
        else
            printf("Alice\n");
    }
    return 0;
}
void bfs(int r1, int c1){
    Q.push(ii(r1, c1)); dist[r1][c1] = 0;   direction[r1][c1] = 'A';

    ii p;   int r2, c2;
    while(!Q.empty()){
        p = Q.front();  Q.pop();
        r1 = p.first,   c1 = p.second;
        for(int i = 0; i < 4; ++i){
            r2 = r1 + dr[i],    c2 = c1 + dc[i];
            if(r2 < 0 || r2 == 6 || c2 < 0 || c2 == 6)  continue;
            if(dist[r2][c2] != UNVISITED)   continue;
            if(blocks.count(make_tuple(r1, c1, r2, c2)))    continue;

            dist[r2][c2] = dist[r1][c1] + 1;
            direction[r2][c2] = dir[i];
            Q.push(ii(r2, c2));
            parent[r2][c2] = ii(r1, c1);
        }
    }
}
Example #30
0
int cal_min()
{
	set <int>::iterator it;
	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j < N; j++)
		{
			if(refer.count(i))	break;
			int f_min = 100000000, s_min = 100000000;
			for(it = refer.begin(); it != refer.end(); it++)
			{
				int k = *it;
				if(f_min > mp[k][i])	f_min = mp[k][i];
				if(s_min > mp[k][j])	s_min = mp[k][j];				
			}
			if(i != j)	mp[i][j] = f_min + s_min;
		}		
	}
	return 0;	
}