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


C++ priority_queue类代码示例

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


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

示例1: CLR

template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q) {
    while (!Q.empty()) Q.pop();
}
开发者ID:pavellevap,项目名称:code_antiplagiat,代码行数:3,代码来源:u40047_436_C_6878649.cpp

示例2: showQueue

// it destroys queue
void showQueue(priority_queue<edge, vector< edge >, compareWeights> queue) {
	while (!queue.empty()) {
		cout << queue.top().v << "-" << queue.top().u << ":" << queue.top().w << endl;
		queue.pop();
	}
}
开发者ID:SkySurferOne,项目名称:ASD,代码行数:7,代码来源:main.cpp

示例3: REP

 REP(i, MAXN) {
     mm[i][MAXN - 1] = num[i][MAXN - 1];
     pq.push(state(i, MAXN - 1, num[i][MAXN - 1]));
 }
开发者ID:Abhay4,项目名称:Algorithm,代码行数:4,代码来源:82.cpp

示例4: init

void init()
{
	int i,j,k;
	scanf("%d",&M);

	while( !heap.empty() ) heap.pop();

	//初始化
	for (i=1;i<=N;++i) 
	{
		dis[i]=INFINITE;
		visit[i]=false;
		path[i]=0;
		bian[i][0]=0;
		for (j=1;j<=N;++j) map[i][j]=INFINITE;
	}

	//读入信息
	for (k=1;k<=M;++k)
	{
		scanf("%d%d",&i,&j);
		scanf("%d",&map[i][j]);
		map[j][i]=map[i][j];

		bian[i][0]++;
		bian[j][0]++;
		bian[i][bian[i][0]]=j;
		bian[j][bian[j][0]]=i;
	}

	//堆初始化
	dis[2]=0;
	path[2]=1;
	node temp;
	temp.dist=0;
	temp.ID=2;
	heap.push(temp);

	int l;
	while (true)
	{
		//从堆中找出最小距离
		while (!heap.empty() && visit[heap.top().ID]) heap.pop();
		if (heap.empty()) break;

		k=heap.top().ID;
		dis[k]=heap.top().dist;
		heap.pop();

		visit[k]=true;
		for (j=1;j<=bian[k][0];++j) 
		{
			l=bian[k][j];
			//满足松弛操作,加入堆
			if (dis[k]+map[k][l]<dis[l]) 
			{
				dis[l]=dis[k]+map[k][l];
				temp.ID=l;
				temp.dist=dis[l];
				heap.push(temp);
			}
			//DP计算方案
			if (visit[l] && dis[l]<dis[k]) path[k]+=path[l];
		}

	}

	printf("%d\n",path[1]);
}
开发者ID:springer126,项目名称:C-World,代码行数:69,代码来源:1036.cpp

示例5: init

void init(){
    for(int i=0;i<MAX_V;i++) G[i].clear();
    while(!que.empty()) que.pop();
}
开发者ID:defense81,项目名称:acm-1,代码行数:4,代码来源:hdu2066.cpp

示例6: insert

void insert(int x) {
    if(queue_b.empty()) {
        queue_b.push(x);
    }
    else{
      if(x > queue_b.top())
        queue_b.push(x);
      else
        queue_s.push(x);
    }
    if(queue_b.size() < queue_s.size() ) {
        queue_b.push(queue_s.top());
        queue_s.pop();
    }
    if(queue_b.size() > queue_s.size() + 1) {
        queue_s.push(queue_b.top());
        queue_b.pop();
    }
}
开发者ID:cxxnzb,项目名称:Alg_problems,代码行数:19,代码来源:Alg_2_A_3.cpp

示例7: update

void update(int pos)
{
	que.push(make_pair(tot[pos],pos));
}
开发者ID:mzry1992,项目名称:workspace,代码行数:4,代码来源:B.cpp

示例8: current

	size_t const current() const { return q.size(); }
开发者ID:Marrary2,项目名称:prep,代码行数:1,代码来源:most_overlapped_point.cpp

示例9: main

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    init();

    int res = game(h, t);

    if (res == 0)
    {
        puts("Draw");
        return 0;
    }

    if (res == 1) puts("Ivan");
    if (res == 2) puts("Zmey");

    if (res == 2)
    {
        int res2 = rec(h, t, res);
        printf("%d\n", res2);
    } else {
        q.push(make(0, h, t));
        dp[h][t] = 0;
        while (!q.empty())
        {
            piii cur = q.top();
            q.pop();
            int x = cur.second.first;
            int y = cur.second.second;

            if (x + y > R) continue;

            int w = cur.first;
            if (dp[x][y] != w) continue;

            int lim = min(x, n);
            for (int i = 1; i <= lim; ++i)
            {
                int dx = H[i].first;
                int dy = H[i].second;
                int nx = x - i + dx;
                int ny = y + dy;

                if (dp[nx][ny] == -1 || dp[nx][ny] > dp[x][y] + 1)
                {
                    dp[nx][ny] = dp[x][y] + 1;
                    q.push(make(dp[nx][ny], nx, ny));
                }
            }

            lim = min(y, m);
            for (int i = 1; i <= lim; ++i)
            {
                int dx = T[i].first;
                int dy = T[i].second;
                int nx = x + dx;
                int ny = y - i + dy;

                if (dp[nx][ny] == -1 || dp[nx][ny] > dp[x][y] + 1)
                {
                    dp[nx][ny] = dp[x][y] + 1;
                    q.push(make(dp[nx][ny], nx, ny));
                }
            }
        }

        printf("%d\n", dp[0][0]);
    }
    return 0;
}
开发者ID:pavellevap,项目名称:code_antiplagiat,代码行数:71,代码来源:u189_48_E_220412.cpp

示例10: main

int main() {
    int N;
    int ans = 0;
    int size = 0;
    scanf("%d", &N);
    while(N--) {
        int type;
        scanf("%d", &type);
        if(type == 2) {
            if(ans) printf("%d\n", ans);
            else puts("No reviews yet");
        } else {
            int x;
            scanf("%d", &x);
            switch(size) {
                case 0: 
                case 1: bad.push(x); break;
                case 2: bad.push(x); ans = bad.top(); bad.pop(); break;
                default: {
                    if (x > ans) {
                        good.push(x);
                        if(size % 3 != 2) {
                            bad.push(ans);
                            ans = good.top();
                            good.pop();
                        }
                    }
                    else {
                        bad.push(x);
                        if(size % 3 == 2) {
                            good.push(ans);
                            ans = bad.top();
                            bad.pop();
                        }
                    }
                }
            }
            ++size;
        }
    }
}
开发者ID:johnathan79717,项目名称:competitive-programming,代码行数:41,代码来源:main.cpp

示例11: main

int main ( ) {
    while(scanf("%d %d", &v, &e) != EOF && v && e) {
        scanf("%d %d", &f, &t);
        for (int i = 0; i < e; i++) {
            scanf("%d %d %d", &a, &b, &w);
            ed.to = b;
            ed.from = a;
            ed.w = w;
            adj[a].push_back(ed);
            ed.to = a;
            ed.from = b;
            adj[b].push_back(ed);
        }
        for (int i = 0; i < v; i++) {
            verts[i].w = -1;
            verts[i].n = i;
        }
        verts[f].w = 0;
        fila.push(verts[f]);

        while (!fila.empty()) {
            nd = fila.top();
            fila.pop();

            for (int i = 0; i < adj[nd.n].size(); i++) {
                if (verts[adj[nd.n][i].to].w == -1 || verts[adj[nd.n][i].to].w > nd.w + adj[nd.n][i].w) {
                    verts[adj[nd.n][i].to].w = nd.w + adj[nd.n][i].w;
                    fila.push(verts[adj[nd.n][i].to]);
                }
            }
        }

        for (int i = 0; i < adj[t].size(); i++) {
            regr.push(adj[t][i]);
        }

        while (!regr.empty()) {
            ed = regr.front();
            regr.pop();
            
            if (ed.w != -1 && verts[ed.to].w + ed.w == verts[ed.from].w) {
                for (int i = 0; i < adj[ed.to].size(); i++) {
                    if (adj[ed.to][i].to = ed.from && adj[ed.to][i].w == ed.w) adj[ed.to][i].w = -1;
                    else regr.push(adj[ed.to][i]);
                }
                for (int i = 0; i < adj[ed.from].size(); i++) if (adj[ed.from][i].to = ed.to && adj[ed.from][i].w == ed.w) adj[ed.from][i].w = -1;
            }
        }
        for (int i = 0; i < v; i++) {
            printf("%d(%d) -> ", i, verts[i].w);
            for (int j = 0; j < adj[i].size(); j++) printf("%d(%d) ", adj[i][j].to, adj[i][j].w);
            printf("\n");
        }

        for(int i = 0; i < v; i++) verts[i].w = -1;

        fila.push(verts[f]);
        while (!fila.empty() ) {
            nd = fila.top();
            fila.pop();

            for (int i = 0; i < adj[nd.n].size(); i++) {
                if (adj[nd.n][i].w != -1 && (verts[adj[nd.n][i].to].w == -1 || verts[adj[nd.n][i].to].w > nd.w + adj[nd.n][i].w)) {
                    verts[adj[nd.n][i].to].w = nd.w + adj[nd.n][i].w;
                    if (adj[nd.n][i].to == t) goto endloop;
                    fila.push(verts[adj[nd.n][i].to]);
                }
            }
        }
endloop:
        printf("%d\n", verts[t].w);
        for (int i = 0; i < e; i++) adj[i].clear();

        while (!fila.empty()) fila.pop();
    }  
}
开发者ID:victorsenam,项目名称:treinos-old,代码行数:76,代码来源:samer08a.v1.cpp

示例12: main

int main()
{
    int tc;
    scanf("%i\n", &tc);
    for(int i = 0; i < tc; i++)
    {
        int n;
        scanf("%i\n", &n);
        while(!asks.empty())
            asks.pop();
        while(!bids.empty())
            bids.pop();
        int stockPrice = -1;
        for(int j = 0; j < n; j++)
        {
            int numero;
            int precio;
            scanf("%s %i shares at %i", temp, &numero, &precio);
            string tipo(temp);
            bool compra = tipo == "buy";
            if(compra)
                bids.push(Oferta(numero, precio));
            else   
                asks.push(Oferta(numero, precio));
            while(!bids.empty() && !asks.empty() && bids.top().precio >= asks.top().precio)
            {
                Oferta bid = bids.top();
                Oferta ask = asks.top();
                bids.pop();
                asks.pop();
                if(bid.numero > ask.numero)
                {
                    bid.numero -= ask.numero;
                    bids.push(bid);
                }
                else if(bid.numero < ask.numero)
                {
                    ask.numero -= bid.numero;
                    asks.push(ask);
                }
                stockPrice = ask.precio;
            }
            if(bids.empty() && asks.empty())
            {
                if(stockPrice == -1)
                    printf("- - -\n");
                else
                    printf("- - %i\n", stockPrice);
            }
            else if(bids.empty())
            {
                if(stockPrice == -1)
                    printf("%i - -\n", asks.top().precio);
                else
                    printf("%i - %i\n", asks.top().precio, stockPrice);
            }
            else if(asks.empty())
            {
                if(stockPrice == -1)
                    printf("- %i -\n", bids.top().precio);
                else
                    printf("- %i %i\n", bids.top().precio, stockPrice);
            }
            else
            {
                if(stockPrice == -1)
                    printf("%i %i -\n", asks.top().precio, bids.top().precio);
                else
                    printf("%i %i %i\n", asks.top().precio, bids.top().precio, stockPrice);
            }
        }
    }
}
开发者ID:Betillo77,项目名称:in-silico,代码行数:73,代码来源:H.cpp

示例13: init

void init() {
    while(!pq.empty()) pq.pop();
    for(int i = 0; i <= maxn; i++) {
        pre[i] = i;
    }
}
开发者ID:VincentXWD,项目名称:algorithm,代码行数:6,代码来源:poj2349.cpp

示例14: AwithTheManhattanDistanceHeuristic

void AwithTheManhattanDistanceHeuristic()
{

    int stateNum = 0;
    while(!PQ.empty())PQ.pop();

    Initstate.g=0;
    Initstate.h=getManhattanDistanceNum(Initstate);

    PQ.push(Initstate);

    printf("Expanding state:\n");
    Initstate.output();


    while (!PQ.empty())
    {
        if(PQ.size()>lenOfQueue){
            lenOfQueue = PQ.size();
        }

        stateNum++;
        Puzzle queueFront = PQ.top();
        PQ.pop();

        printf("g(n)=%d  " ,queueFront.g);
        printf("h(n)=%d  ",queueFront.h);
        outputExpanding(queueFront);

        if(judgeComplete(queueFront))
        {
            break;
        }
        else
        {
            Puzzle tPuzzle = queueFront;
            if(tranform(LEFT,tPuzzle)&&!judgeSame(tPuzzle,queueFront))
            {
                tPuzzle.g = queueFront.g+1;
                tPuzzle.h = getManhattanDistanceNum(tPuzzle);
                giveFatherValue(tPuzzle,queueFront);
                PQ.push(tPuzzle);
                stateNum++;
            }
            tPuzzle = queueFront;
            if(tranform(RIGHT,tPuzzle)&&!judgeSame(tPuzzle,queueFront))
            {
                tPuzzle.g = queueFront.g+1;
                tPuzzle.h = getManhattanDistanceNum(tPuzzle);
                giveFatherValue(tPuzzle,queueFront);
                PQ.push(tPuzzle);
                stateNum++;
            }
            tPuzzle = queueFront;
            if(tranform(UP,tPuzzle)&&!judgeSame(tPuzzle,queueFront))
            {
                tPuzzle.g = queueFront.g+1;
                tPuzzle.h = getManhattanDistanceNum(tPuzzle);
                giveFatherValue(tPuzzle,queueFront);
                PQ.push(tPuzzle);
                stateNum++;
            }
            tPuzzle = queueFront;
            if(tranform(DOWN,tPuzzle)&&!judgeSame(tPuzzle,queueFront))
            {
                tPuzzle.g = queueFront.g+1;
                tPuzzle.h = getManhattanDistanceNum(tPuzzle);
                giveFatherValue(tPuzzle,queueFront);
                PQ.push(tPuzzle);
                stateNum++;
            }
        }
    }
    printf("%d\n",stateNum);


}
开发者ID:ninocanna,项目名称:8-puzzle-solver,代码行数:77,代码来源:main.cpp

示例15: main

int main(){
    int n,l,i,bl;
    scanf("%d%d",&n,&l);
    for(i=0;i<l;i++){
        //scanf("%d",&b[i]);
        b[i]=scanInt();
        maxq.push(b[i]);
        minq.push(b[i]);
    }
    if(maxq.top()-minq.top()+1==l) ans++;
    bl=0;
    while(i<n){
        black[b[bl]]=1;
        //scanf("%d",&b[i]);
        b[i]=scanInt();
        maxq.push(b[i]);
        minq.push(b[i]);
        while(black[maxq.top()])
            maxq.pop();
        while(black[minq.top()])    
            minq.pop();
        if(maxq.top()-minq.top()+1==l) ans++;
        bl++;
        i++;
    }
    printf("%d",ans);
    return 0;
}
开发者ID:sriankit,项目名称:cpp_codes,代码行数:28,代码来源:mytown.cpp


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