当前位置: 首页>>代码示例>>C++>>正文


C++ queue::push方法代码示例

本文整理汇总了C++中queue::push方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::push方法的具体用法?C++ queue::push怎么用?C++ queue::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在queue的用法示例。


在下文中一共展示了queue::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BFS

int BFS()
{
    while (!q.empty())
    {
        auto u = q.front();
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            pair<int, int> v = make_pair(u.first + d_dist[i].first, u.second + d_dist[i].second);
            if(v.first < 0 || v.first >= 2000 || v.second < 0 || v.second >= 2000)
                continue;
            if (dist[v.first][v.second] == -1)
            {
                dist[v.first][v.second] = dist[u.first][u.second] + 1;
                if (mark[v.first][v.second])
                    return dist[v.first][v.second];
                q.push(v);
            }
        }
    }
    return 0;
}
开发者ID:ShadyF,项目名称:Competitive-Programming-Problems,代码行数:22,代码来源:11101+-+Mall+Mania.cpp

示例2: timeGetTime

void *ReceiveThread(void *)
#endif
{
	char buf[10000];
	while (true) {
		fgets(buf, 10000, stdin);
		buf[strlen(buf) - 1] = 0; // 改行コードを消す。

		if (strncmp(buf, "quit", strlen("quit")) == 0) {
			while (commandQueue.size() > 0) {
				// エンジン設定ダイアログでOKを押すと、setoptionとquitが続けて送られてくる。
				// その時、setoptionの内容を実行する前にexit()を呼ばないよう、quitコマンドより
				// 前に受信したコマンドが全て実行されてから終了するようにする。
				// 本当は、commandQueueのサイズが0だからといって、それ以前のコマンドが本当に
				// 実行されたという保証はないが(popしただけで、まだ実行前の可能性もあるので)、
				// setoptionに関しては実行に200msもかかることはないので、この対策だけで済ませる
				// ことにする。
				Sleep(200);
			}
			// 終了前にクリティカルセクションオブジェクトを破棄。
			DeleteCriticalSection(&cs);
			// quitを受信したらエンジンを終了する。
			exit(0);
		}
		EnterCriticalSection(&cs); // クリティカルセクションに入る。
		if (strncmp(buf, "stop", strlen("stop")) == 0) {
			isStopReceived = true;
		}
		if (strncmp(buf, "ponderhit", strlen("ponderhit")) == 0) {
			ponderhitReceiveTime = timeGetTime();
		}
		if (strncmp(buf, "gameover", strlen("gameover")) == 0) {
			isStopReceived = true; // 先読み中にgameoverが送られてきた場合、すぐ思考を打ち切る。
		}
		string commandStr = buf;
		commandQueue.push(commandStr); // コマンドをキューに追加。
		LeaveCriticalSection(&cs); // クリティカルセクションを出る。
	}
}
开发者ID:inaniwa3,项目名称:inaniwa-shogi,代码行数:39,代码来源:Lesserkai.cpp

示例3: spfa

void spfa()
{
	while (!Q.empty())
	{
		int u = Q.front()&((1<<MAX)-1), st = Q.front()>>MAX;
		Q.pop();
		inq[u][st] = 0;
		for (int i = head[u]; i != -1; i = next[i])
		{
			int nst = st|bit[v[i]];
			if (d[u][st]+w[i] < d[v[i]][nst])
			{
				d[v[i]][nst] = d[u][st]+w[i];
				if (nst == st && !inq[v[i]][nst])
				{
					Q.push(nst<<MAX|v[i]);
					inq[v[i]][nst] = 1;
				}
			}
		}
	}
}
开发者ID:aroslhy,项目名称:acm,代码行数:22,代码来源:斯坦纳树_hdu_4085.cpp

示例4: main

int main() {
#   ifdef _DEBUG
        freopen("i.in", "r", stdin);
#   else
        freopen("i.in", "r", stdin);
        freopen("i.out", "w", stdout);
#   endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    words.reserve(20000);
    int i;
    string s;
    while (cin >> s) {
        if (s == "<text>") {
            q.push((lastMap = new Memory));
            if (q.size() > 7) {
                Memory* toDel = q.front();
                for (i = 0; i < (int)words.size(); i++)
                    sevenDaysMap.words[i].count -= toDel->words[i].count;
                q.pop();
            }
            while (cin >> s, s != "</text>") {
                if (s.length() < 4)
                    continue;
                map<string, int>::iterator lb = wordMap.lower_bound(s);
                int id;
                if (lb != wordMap.end() && !wordMap.key_comp()(s, lb->first)) {
                    //existing.
                    id = lb->second;
                } else {
                    //new.
                    id = words.size();
                    wordMap.insert(lb, make_pair(s, id));
                    words.push_back(s);
                }
                lastMap->words[id].count++;
                sevenDaysMap.words[id].count++;
            }
        } else if (s == "<top") {
开发者ID:Ralor,项目名称:acm-conventions,代码行数:39,代码来源:i.cpp

示例5: make_snake

void make_snake(vector<Cor> &snake,int pos,int cost){
	if(pos>=snake.size()){
		if(!Done.count(snake)){
			Done.insert(snake);
			if(check(snake,snake.size()-1))
				Q.push(state(snake,cost));
		}
		return;
	}

	for(int r=0;r<6;r++){
		snake[pos].x+=dx[r]; snake[pos].y+=dy[r];
		if(!Rock.count(snake[pos])){
			if(pos+1>=snake.size() || is_next(snake[pos],snake[pos+1]) )
				if(check(snake,pos) )
					make_snake(snake,pos+2,cost);
		}
		snake[pos].x-=dx[r];snake[pos].y-=dy[r];
	}
	if(check(snake,pos))
		make_snake(snake,pos+1,cost);
}
开发者ID:Tom1031,项目名称:AOJ,代码行数:22,代码来源:1143.cpp

示例6: onepath

	void onepath(TreeNode *root, int sum, queue<int> father) {
		if(root==NULL)	/* because child may be empty, it can be empty */
			return;
		/* judge if reach the leaf */
		if(root->right==NULL&&root->left==NULL){
			if(root->val==sum){
				vector<int> findit;
				while(!father.empty()){
					int value = father.front();
					findit.push_back(value);
					father.pop();
				}
				findit.push_back(sum);
				vec_result.push_back(findit);
			}
			return;
		}
		father.push(root->val);
		sum-=root->val;
		onepath(root->left,sum,father);
		onepath(root->right,sum,father);
	}
开发者ID:duansy2002,项目名称:Linux-C,代码行数:22,代码来源:Path+Sum+II.cpp

示例7: main

int main(int argc, const char * argv[]) {
    int i,j,m,n,k;
    
    //读入
    sqr sq;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&s[i][j]);
            sq.a[i][j]=s[i][j];
        }
    }
    sq.deep = 0;
    q.push(sq);
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&t[i][j]);
        }
    }
    
    printf("%d\n",bfs());
    return 0;
}
开发者ID:wzcjj,项目名称:cjj1,代码行数:22,代码来源:bfs.cpp

示例8: dist

int dist(int t, int si, int sj, int ti, int tj) {
	if (si==ti && sj==tj) {
		return 0;
	}
	if (D[t][si][sj][ti][tj] != -1) {
		return D[t][si][sj][ti][tj];
	}

	Q = queue< pair<int, int> >();
	memset(done, 0, sizeof done);
	done[t][si][sj] = 1;
	int ret = -1;
	int sz = 0;
	Si = si;
	Sj = sj;
	Q.push(make_pair(si, sj));

	while (!Q.empty()) {
		if (sz == 0) {
			sz = Q.size();
			++ret;
		}
		--sz;
		int i = Q.front().first;
		int j = Q.front().second;
		Q.pop();
		if (D[t][si][sj][i][j]==-1 || ret<D[t][si][sj][i][j]) {
			D[t][si][sj][i][j] = ret;
		} 

		if (i==ti && j==tj) {
			return ret;
		}

		expand(i, j, t);
	}

	return -1;
}
开发者ID:alxsoares,项目名称:contest-problem-solutions,代码行数:39,代码来源:CollectingRiders.cpp

示例9: BFS1

void BFS1()
{
    int i, a, b, x, y;
    while(qu1.size())
    {
        a = qu1.front();
        qu1.pop();
        b = qu1.front();
        qu1.pop();
        for(i=0; i<4; i++)
        {
            x = a+xx[i];
            y = b+yy[i];
            if(x<0 or y<0 or x==r or y==c or level[0][x][y]!= 1000006 or mat[x][y]=='#' or mat[x][y]=='F') continue;
            level[0][x][y] = level[0][a][b] + 1;
            qu1.push(x);
            qu1.push(y);

        }

    }
}
开发者ID:RafikFarhad,项目名称:Code_is_fun,代码行数:22,代码来源:B+Fire.cpp

示例10: make_map_temp

void make_map_temp (int x , int y , int type) {
    for (int i = 0 ; i < 3 ; i++) {
        for (int j = 0 ; j < 3 ; j++) {
            map_temp[i][j] = map_cur[i][j];
        }
    }

    switch (type) {
        case 1:
            swap (&map_temp[x][y] , &map_temp[x-1][y]);
            /*for (int i = 0 ; i < 3 ; i++) {
                for (int j = 0 ; j < 3 ; j++) {
                    map_temp[i][j] = map_cur[i][j];
                }
            }*/
            break;
        case 2:
            swap (&map_temp[x][y] , &map_temp[x+1][y]);
            break;
        case 3:
            swap (&map_temp[x][y] , &map_temp[x][y-1]);
            break;
        case 4:
            swap (&map_temp[x][y] , &map_temp[x][y+1]);
            break;
        default:
            return;
    }
    int value = 0;

    for (int i = 0 ; i < 3 ; i++) {
        for (int j = 0 ; j < 3 ; j++) {
            value = value*10 + map_temp[i][j];
        }
    }
    st_que.push (value);
    int dis_temp = dis_map[st_que.front()];
    dis_map.insert (pair<int,int>(value,dis_temp+1));
}
开发者ID:buddyhelloXD,项目名称:mytinywebserver,代码行数:39,代码来源:bashuma.cpp

示例11: main

int main() {
	while (scanf("%d%d", &m, &n) == 2 && (n || m)) {
		memset(d, 0x1F, sizeof(d));
		memset(inq, 0, sizeof(inq));
		while (!q.empty()) q.pop();
		for (int i = 0; i < n; ++ i)
			for (int j = 0; j < m; ++ j) {
				scanf("%s", buf);
				if (!isdigit(buf[0])) g[i][j] = -1;
				else g[i][j] = buf[0] - '0';
				if (buf[0] == 'T') g[i][j] = 0;
				if (buf[0] == 'S') {
					q.push(record(i, j, 0));
					q.push(record(i, j, 1));
					d[i][j][0] = d[i][j][1] = 0;
					inq[i][j][0] = inq[i][j][1] = 1;
				}
			}
		printf("%d\n", bfs());
	}
	return 0;
}
开发者ID:mrain,项目名称:acm,代码行数:22,代码来源:d.cpp

示例12: main

int main(){
    freopen("in.txt","r",stdin);
    int kase;
    scanf("%d",&kase);
    queue<tt> empty;
    while (kase--){

        scanf("%d %d",&row,&col);
        q=empty;
        for (int i=0;i<row;++i){
            scanf("%s",mp[i]);
            for (int j=0;j<col;++j){
                fire[i][j]=INF;
                if ( mp[i][j]=='F' ){
                    tmp.r=i;
                    tmp.c=j;
                    tmp.val=0;
                    fire[i][j]=0;
                    q.push(tmp);
                }else if ( mp[i][j]=='J' ){
                    joe.r=i;
                    joe.c=j;
                    joe.val=0;
                }
            }
        }
        BFSfire();


        int rr=BFSjoe();
        if ( rr== -1 ){
            printf("IMPOSSIBLE\n");
        }else{
            printf("%d\n",rr);
        }
    }
    return 0;

}
开发者ID:TrojanMe,项目名称:UVa-Problems,代码行数:39,代码来源:11624.cpp

示例13:

void
Java_cc_openframeworks_OFAndroid_onTouchMoved(JNIEnv*  env, jclass  thiz, jint id,jfloat x,jfloat y,jfloat pressure){
	ofTouchEventArgs touch;
	touch.id = id;
	touch.x = x;
	touch.y = y;
	touch.pressure = pressure;
	touch.type = ofTouchEventArgs::move;
	if(threadedTouchEvents){
		ofNotifyMouseMoved(x,y);
		ofNotifyMouseDragged(x,y,0);
		ofNotifyEvent(ofEvents().touchMoved,touch);
	}else{
		mutex.lock();
		if(accumulateTouchEvents && !touchEventArgsQueue.empty() && touchEventArgsQueue.back().type==ofTouchEventArgs::move){
			touchEventArgsQueue.back() = touch;
		}else{
			touchEventArgsQueue.push(touch);
		}
		mutex.unlock();
	}
}
开发者ID:Kenn2013,项目名称:openFrameworks,代码行数:22,代码来源:ofAppAndroidWindow.cpp

示例14: add_customer

   void add_customer( int serv_time )
   {

      //sets timer to 0 for first input, since i reset it on pop its
      //needed for first entry.
      if( time_limit.empty() )
      {  
         timer = 0;
      }

      //puts the serv_time on the queue of time_limits
      time_limit.push( serv_time );

      //add customer to line
      in_line++;

      if( in_line == 6 )
      {
         status = 'i';
      }
 
   }
开发者ID:hosstay,项目名称:Grocery-Store-Queue,代码行数:22,代码来源:cashier.hpp

示例15: scanf

main()
{
    int n,k ; scanf("%d%d",&n,&k) ;
    while(k--){int x ; scanf("%d",&x) ; q1.push(x) ;}
    scanf("%d",&k) ;
    while(k--){int x ; scanf("%d",&x) ; q2.push(x) ;}
    for(int cnt=0;cnt<100000000;cnt++)
    {
        if(q1.empty()){printf("%d 2\n",cnt) ; return 0 ;}
        if(q2.empty()){printf("%d 1\n",cnt) ; return 0 ;}
        int x=q1.front() ; q1.pop() ;
        int y=q2.front() ; q2.pop() ;
        if(x>y) q1.push(y) , q1.push(x) ;
        else q2.push(x) , q2.push(y) ;
    }
    printf("-1\n") ;
}
开发者ID:a00012025,项目名称:Online_Judge_Code,代码行数:17,代码来源:546-C.cpp


注:本文中的queue::push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。