• P1177快速排序


    这是一个快速排序的模板题。拿到题后便写了quicksort(确定一个基准数,利用两个哨兵,把大的放右边,小的放左边,再递归实现排序),但是竟然TLE了60pts(???),于是翻看dalao们的题解,发现了堆排序(在清北学会了,但是一个学期后给忘了),然后看到了一个multiset(set去重,它不去),这个STL插入后自动排序,然后利用迭代器进行输出。STL大法好。

    1.要养成用标准读入与输出的习惯

    2.善于利用STL,平日还要多加积累

    3.牢记迭代器语法

    代码:

     1 #include<iostream>
     2 #include<set>
     3 #include<cstdio>
     4 #define N 1000005
     5 using namespace std;
     6 
     7 int n;
     8 int main(){
     9     multiset<int>a;
    10     scanf("%d",&n); 
    11     int x;
    12     for(int i=1;i<=n;i++){
    13         scanf("%d",&x);
    14         a.insert(x);
    15     }
    16     multiset<int>::iterator it;
    17     for(it=a.begin();it!=a.end();it++){
    18         cout<<*it<<" ";
    19     } 
    20     return 0;
    21 }
    待到oi十一月,我花开后百花杀。
  • 相关阅读:
    Wiggle Sort II
    Coin Change
    MPLS LDP 知识要点
    MPLS Aggreate & Untag
    Lab MPLS隐藏标签显示
    Lab MPLS过滤标签转发
    MPLS MTU Aggregation
    研究MPLS MTU的问题
    Lab 利用MPLS解决BGP路由黑洞
    MPLS 标签保留
  • 原文地址:https://www.cnblogs.com/china-mjr/p/11215492.html
Copyright © 2020-2023  润新知