zoukankan      html  css  js  c++  java
  • sort

    sort

    Time Limit : 6000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 139   Accepted Submission(s) : 39

    Font: Times New Roman | Verdana | Georgia

    Font Size:

    Problem Description

    给你n个整数,请按从大到小的顺序输出其中前m大的数。

    Input

    每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。

    Output

    对每组测试数据按从大到小的顺序输出前m大的数。

    Sample Input

    5 3
    3 -35 92 213 -644
    

    Sample Output

    213 92 3
    

    Hint

    Hint
    请用VC/VC++提交

    Author

    LL

    Source

    ACM暑期集训队练习赛(三)
    这题明显要用优先队列

    #include<iostream>
    #include<queue>
    using namespace std;
    int main()
    {
     int n,m;
     while(scanf("%d %d",&n,&m)!=EOF)
     {
      priority_queue<int> q;
      int i=0;
      while(i++<n)
      {
       int u;
       scanf("%d",&u);
       q.push(u);
      }
      i=0;
      while(i++<m)
      {
       int w;
       w=q.top();
       q.pop();
       if(i==1)
        printf("%d",w);
       else
        printf(" %d",w);
      
      }
      printf(" ");
      


     }


    }

     
  • 相关阅读:
    web 服务器安全防范
    Liunx 挂载磁盘
    服务器被挖矿
    PHP 实时生成并下载超大数据量的 Excel 文件
    liunx php-fpm
    Liunx PHP安装Redis扩展
    CentOS 安装Redis
    Window PHP安装Redis 扩展
    web开发
    汇合confluence
  • 原文地址:https://www.cnblogs.com/2013lzm/p/3259322.html
Copyright © 2011-2022 走看看