2019 GDUT Rating Contest III : Problem A. Out of Sorts
题面:
A. Out of Sorts
题目描述:
题目分析:




1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <cmath>
5 #include <set>
6 #include <algorithm>
7 using namespace std;
8 const int maxn = 1e6+5;
9 int n;
10 struct node{
11 long long a; //要进行排序的元素
12 long long p; //下标
13 };
14 node A[maxn];
15
16 bool cmp(node x, node y){ //比较函数
17 return x.a < y.a; //从小到大排序
18 }
19
20 int main(){
21 scanf("%d", &n);
22
23 for(int i = 0; i < n; i++){
24 scanf("%lld", &A[i].a);
25 A[i].p = i;
26 }
27
28 stable_sort(A, A+n, cmp); //排序
29
30 int moo = 0; //初始化最大值
31 for(int i = 0; i < n; i++){
32 //往前面移动过的数就是之前没排序前的下标大于排序后的下标
33 //这里可以与求最大值结合在一起判断
34 if(A[i].p-i > moo){ //A[i]-i就是移动的步数
35 moo = A[i].p-i;
36 }
37 }
38
39 printf("%d\n", moo+1); //记得要+1
40 return 0;
41 }
2019 GDUT Rating Contest III : Problem A. Out of Sorts的更多相关文章
- 2019 GDUT Rating Contest III : Problem D. Lemonade Line
题面: D. Lemonade Line Input file: standard input Output file: standard output Time limit: 1 second Memo ...
- 2019 GDUT Rating Contest III : Problem E. Family Tree
题面: E. Family Tree Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe
题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2019 GDUT Rating Contest II : Problem F. Teleportation
题面: Problem F. Teleportation Input file: standard input Output file: standard output Time limit: 15 se ...
- 2019 GDUT Rating Contest I : Problem H. Mixing Milk
题面: H. Mixing Milk Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest I : Problem A. The Bucket List
题面: A. The Bucket List Input file: standard input Output file: standard output Time limit: 1 second Me ...
- 2019 GDUT Rating Contest I : Problem G. Back and Forth
题面: G. Back and Forth Input file: standard input Output file: standard output Time limit: 1 second Mem ...
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- 2019 GDUT Rating Contest II : Problem C. Rest Stops
题面: C. Rest Stops Input file: standard input Output file: standard output Time limit: 1 second Memory ...
随机推荐
- 记一次 Billu_b0x渗透
目录: 0x01 寻找ip 1.这边我们是使用的nmap来寻找我们的靶机IP地址,开始Ip是1,结束是254,153是我kali的ip,所以158就是我们的靶机的ip地址了. 2. 查看端口服务 这边 ...
- TypeScript TSConfig All In One
TypeScript TSConfig All In One tsconfig.json https://www.typescriptlang.org/tsconfig https://www.typ ...
- 如何给 GitHub 添加 SSH key, 如何生成 SSH key 详细图文教程!
如何给 GitHub 添加 SSH key, 如何生成 SSH key 详细图文教程! 一. 生成 SSH key https://ide.c9.io/xgqfrms/ 创建一个空项目:(或使用 ...
- MongoDB Up and Going
# MongoDB Up and Going https://ide.c9.io/xgqfrms/mongodb # MongoDB 教程 https://www.runoob.com/mongodb ...
- 05.其他创建numpy数组的方法
>>> import numpy as np >>> np.zeros(10,dtype=int) array([0, 0, 0, 0, 0, 0, 0, 0, 0 ...
- Scrapy 项目:QuotesBot
QuotesBot This is a Scrapy project to scrape quotes from famous people from http://quotes.toscrape.c ...
- hadoop环境搭建:完全分布式
目录 1.硬件配置 2.软件版本 3.准备工作 3.1.建立虚拟机,网络设置为桥接模式 3.2.更改主机名 3.3.绑定主机名和IP,建立各主机间的联系 3.4.关闭防火墙 3.5.配置宿主机host ...
- 自己的Scrapy框架学习之路
开始自己的Scrapy 框架学习之路. 一.Scrapy安装介绍 参考网上资料,先进行安装 使用pip来安装Scrapy 在开始菜单打开cmd命令行窗口执行如下命令即可 pip install Scr ...
- SpringBoot读取资源目录下的文件
需要读取resources目录下的文件,那么方法如下: 假设在资源目录下的template目录下有一个文件a.txt,获取到文件流的方式 InputStream stream = this.getCl ...
- Spring @Transactional注解和ReentrantLock同步锁同时使用不能同步的问题
结论:如果在service层的方法上同时使用事务和同步锁无法保证数据同步. 1 @Service 2 public class ServiceImpl{ 3 4 private static Lock ...