从0开始学算法--排序(1.12c++利用标准库排序)
1,简单数组按升序排序
sort(a,a+n);
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue> using namespace std; const int maxn=1e5+;
int a[maxn];
int n; int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=;i<n;i++){
printf("%d ",a[i]);
}printf("\n");
return ;
}
2.简单数组降序排序
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue> using namespace std; const int maxn=1e5+;
int a[maxn];
int n; bool complare(int a,int b){
return a>b;
} int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n,complare);
for(int i=;i<n;i++){
printf("%d ",a[i]);
}printf("\n");
return ;
}
3.结构体排序
struct node{
int a,b;
double c;
}an[maxn];
bool cmp(node x,node y){
if(x.a!=y.a)return x.a<y.a;
if(x,b!=y.b)return x.b>y.b;
return x.c<y.c;
}
sort(an,an+n,cmp);
4.vector排序
sort(v.begin(),v.end());
5.vector结构体排序
struct job{
int j,b;
bool operator<(cost job &x)const{
return j>x.j;
}
};
vector<job>v;
sort(v.begin(),v.end);
从0开始学算法--排序(1.12c++利用标准库排序)的更多相关文章
- 从0开始学爬虫10之urllib和requests库与github/api的交互
urllib库的使用 # coding=utf-8 import urllib2 import urllib # htpbin模拟的环境 URL_IP="http://10.11.0.215 ...
- 0算法基础学算法 搜索篇第二讲 BFS广度优先搜索的思想
dfs前置知识: 递归链接:0基础算法基础学算法 第六弹 递归 - 球君 - 博客园 (cnblogs.com) dfs深度优先搜索:0基础学算法 搜索篇第一讲 深度优先搜索 - 球君 - 博客园 ( ...
- freeRTOS V10.0.1移植到STM32F407标准库 - 环境Keil5
最近因为工作需要用到FreeRTOS,其实开始本人内心是拒绝的因为自己只学习过UCOSIII还没实际上过什么大又复杂的工程,但是谁让FreeRTOS他是Free的呢公司成本考虑肯定是不会选择USOS的 ...
- 《OD学算法》排序
参考 http://www.cnblogs.com/kkun/archive/2011/11/23/2260312.html http://blog.csdn.net/wuxinyicomeon/ar ...
- 看动画学算法之:排序-count排序
目录 简介 count排序的例子 count排序的java实现 count排序的第二种方法 count排序的时间复杂度 简介 今天我们介绍一种不需要作比较就能排序的算法:count排序. count排 ...
- 几种排序算法的学习,利用Python和C实现
之前学过的都忘了,也没好好做过总结,现在总结一下. 时间复杂度和空间复杂度的概念: 1.空间复杂度:是程序运行所以需要的额外消耗存储空间,一般的递归算法就要有o(n)的空间复杂度了,简单说就是递归集算 ...
- 决策树之ID3、C4.5、C5.0等五大算法
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- C5.0决策树之ID3.C4.5.C5.0算法 ...
- 1187: 零起点学算法94——今年暑假不AC(Java)
1187:零起点学算法94--今年暑假不AC Time Limit: 1 Sec Memory Limit: 32 MB 64bit IO Format: %lld Description " ...
- STL笔记(6)标准库:标准库中的排序算法
STL笔记(6)标准库:标准库中的排序算法 标准库:标准库中的排序算法The Standard Librarian: Sorting in the Standard Library Matthew A ...
随机推荐
- Linux系统WEB服务之Nginx基础入门
一.Nginxi简介 Nginx是什么?它是一个开源.高性能的WEB服务器软件和代理服务器软件,由俄罗斯人Igor Sysoev 开发实现.它的功能主要分三类,第一是它作为一个WEB服务软件使用:第二 ...
- python--虚拟环境的使用
下载virtualenv # pip3 install virtualenv 创建虚拟环境(自定义虚拟环境名称为Aechery_env) # virtualenv -p python3 Archery ...
- [CQOI2015]选数(莫比乌斯反演,杜教筛)
[CQOI2015]选数(luogu) Description 题目描述 我们知道,从区间 [L,H](L 和 H 为整数)中选取 N 个整数,总共有 (H-L+1)^N 种方案. 小 z 很好奇这样 ...
- Android中实现一个简单的逐帧动画(附代码下载)
场景 Android中的逐帧动画,就是由连续的一张张照片组成的动画. 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 ...
- 关于使用kms时遇到的there is nothing to do here
我讲一下我自己的解决方法 ------------------------------------ 这个错误还是很明显的,没事干,如果不是kms的锅的话,那么就是字面上的问题了 ----------- ...
- python——面向对象(4),单继承
"""class 类名(object<父类>)继承:子类继承父类.单继承:""" class A(object): " ...
- 修改PR Cs6,PS Cs6,AU Cs6的启动界面
转载来源:https://jingyan.baidu.com/article/09ea3ede00aeedc0aede39ca.html 百度了很多,只见PS Cs6的启动界面修改教程,PR,AU C ...
- webpack打包进行丑化压缩遇到(TypeError Cannot read property 'compilation' of undefined)问题
今天再重新配置老项目node打包环境的时候遇到了一个问题. 在打包的时候报: TypeError: Cannot read property 'compilation' of undefined 错误 ...
- 【Java】简易Socket连接实现
客户端: import java.io.*; import java.net.Socket; import java.text.SimpleDateFormat; import java.util.D ...
- 最小生成树算法总结(Kruskal,Prim)
今天复习最小生成树算法. 最小生成树指的是在一个图中选择n-1条边将所有n个顶点连起来,且n-1条边的权值之和最小.形象一点说就是找出一条路线遍历完所有点,不能形成回路且总路程最短. Kurskal算 ...