zoukankan      html  css  js  c++  java
  • POJ2442 优先队列

    优先队列不同于普通队列,它分为最大优先队列和最小优先队列,当你写成priority_queue<int >a时,它默认为最大优先队列

    最大优先队列即,当它用  a.top()时   从队列中寻找最大的数值,当它用  a.pop()时   从队列中删除最大的数值,

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    #include <queue>
    #include <algorithm>
    using namespace std;

    int main()
    {
    priority_queue<int> a;

    int t;
    scanf("%d",&t);
    while(t--)
    {


    int i,j,k,x[3000],y[3000],m,n;
    scanf("%d %d",&m,&n);
    for(i=0;i<n;i++)
    scanf("%d",&x[i]);
    sort(x,x+n);

    for(i=1;i<m;i++)
    {
    for(int g=0;g<n;g++)
    scanf("%d",&y[g]);


    for(k=0;k<n;k++)
    a.push(x[k]+y[0]);

    for(j=1;j<n;j++)
    for(k=0;k<n;k++)
    {
    if(y[j]+x[k]>a.top())
    break;

    a.pop();
    a.push(y[j]+x[k]);
    }
    for(k=0;k<n;k++)
    {
    x[k]=a.top();
    a.pop();
    }
    sort(x,x+n);
    }

    for(i=0;i<n-1;i++)
    cout << x[i] << " " ;
    cout << x[n-1] << endl;
    }
    return 0;
    }

  • 相关阅读:
    2015多校.Zero Escape (dp减枝 && 滚动数组)
    UVa-11809
    UVa-1588 Kickdown
    UVa-1587
    UVa-10340
    UVa-202
    UVa-1368
    UVa-232 Crossword Answers
    UVa-227
    UVa-455 Periodic Strings
  • 原文地址:https://www.cnblogs.com/woyaocheng/p/4867375.html
Copyright © 2011-2022 走看看