zoukankan      html  css  js  c++  java
  • hdu 2020

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2020

    思路:优先队列水过priority_queue

     1 #include <cstdio>  
     2 #include <iostream>  
     3 #include<algorithm>
     4 #include<math.h> 
     5 #include <string.h>  
     6 #include<queue>
     7 using namespace std;
     8 
     9 
    10 class T
    11 {
    12     public:
    13         int x;
    14     T(int a):x(a)
    15     {
    16         
    17     }
    18     
    19 };
    20 
    21 
    22 bool operator < (const T &t1,const T &t2)
    23 {
    24     return fabs(t1.x)<fabs(t2.x);    //常规降序 
    25 }
    26 
    27 int main()
    28 {
    29     int num,n;
    30     while(scanf("%d",&num),num)
    31     {
    32         priority_queue<T> q;
    33         
    34         for(int i=0;i<num;i++)
    35         {
    36             scanf("%d",&n);
    37             q.push(T(n));
    38         }
    39         int len=q.size();    
    40         for(int i=0;i<len-1;i++)
    41         {
    42             T t=q.top();q.pop();
    43             cout<<t.x<<" ";
    44         }
    45         T a=q.top();
    46         cout<<a.x<<endl;    
    47     }
    48     return 0;
    49     
    50  }
    51  
  • 相关阅读:
    linux_进程管理
    Linux-日志管理
    Httpd
    Linux-源码安装包管理
    Linux-计划任务管理
    Linux-LVM管理
    Linux-系统磁盘管理
    Linux-yum工具的使用
    Linux-rpm包管理
    Linux-网络进阶管理
  • 原文地址:https://www.cnblogs.com/pter/p/4988886.html
Copyright © 2011-2022 走看看