本文整理汇总了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();
}
示例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();
}
}
示例3: REP
REP(i, MAXN) {
mm[i][MAXN - 1] = num[i][MAXN - 1];
pq.push(state(i, MAXN - 1, num[i][MAXN - 1]));
}
示例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]);
}
示例5: init
void init(){
for(int i=0;i<MAX_V;i++) G[i].clear();
while(!que.empty()) que.pop();
}
示例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();
}
}
示例7: update
void update(int pos)
{
que.push(make_pair(tot[pos],pos));
}
示例8: current
size_t const current() const { return q.size(); }
示例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;
}
示例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;
}
}
}
示例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();
}
}
示例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);
}
}
}
}
示例13: init
void init() {
while(!pq.empty()) pq.pop();
for(int i = 0; i <= maxn; i++) {
pre[i] = i;
}
}
示例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);
}
示例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;
}