Codeforces Round #258 (Div. 2) B. Sort the Array
来源:互联网 发布:毕业论文致谢 知乎 编辑:程序博客网 时间:2024/04/30 04:06
题意:给你一个数组,问你是否可以通过翻转一个区间[l,r]内的数字。来使得这个数组完全有序。
解法:我们下对每个数字进行标号,然后对值进行排序,之后就只需要处理标号即可。
找到标号与其位置不同的区间,判断其翻转过来标号是不是一个1-N的的排列即可。
#include <bits/stdc++.h>#define _ ios_base::sync_with_stdio(0);cin.tie(0);#define INF 0x3f3f3f3f#define eps 1e-6typedef long long LL;const double pi = acos(-1.0);const long long mod = 1e9 + 2015;using namespace std;struct data{ int pos; int val;}p[100005];bool cmp(const data a,const data b){ return a.val < b.val;}int main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("int.txt","r",stdin); //freopen("out.txt","w",stdout); int N; cin >> N; int MIN = N; int MAX = 1; for(int i = 1;i <= N;i++) { cin >> p[i].val; p[i].pos = i; } sort(p + 1,p + N + 1,cmp); for(int i = 1;i <= N;i++) { if(p[i].pos != i) { MIN = min(MIN,i); MAX = max(MAX,i); } } int ok = 1; for(int i = MIN;i <= MAX;i++) if(p[i].pos != MAX - i + MIN) { ok = 0; break; } if(MIN >= MAX) printf("yes\n1 1\n"); else if(ok) printf("yes\n%d %d\n",MIN,MAX); else puts("no"); return 0;}
0 0
- Codeforces Round #258 (Div. 2) 2B Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2)——B. Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array (模拟)
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
- Codeforces Round #258 (Div. 2)——B. Sort the Array(STL-reverse)
- Codeforces #258 (Div. 2) B. Sort the Array
- Codeforces Div. 2 #258-B. Sort the Array
- Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array
- Codeforces Round #138 (Div. 2) B. Array
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #312 (Div. 2) B. Amr and The Large Array
- Codeforces Round #312 (Div. 2)-B. Amr and The Large Array-暴力
- 使用tensorflow构建简单卷积神经网络
- java学习日记_4:数组的学习1.1
- SpringMVC 配置文件
- 搜索引擎搜索技巧系列视频
- Android中的序列化浅析
- Codeforces Round #258 (Div. 2) B. Sort the Array
- sitemesh中的decorators.xml的用法
- Centos7安装Nginx以及与FastDFS的结合
- 输入一个字符串,内有数字和非数字字符。
- 深度学习笔记5:池化层的实现
- Javascript基础-介绍、实现、输出
- BZOJ1635 [Usaco2007 Jan]Tallest Cow 最高的牛 数列差分
- oracle执行了shutdown某个实例之后,如何重新启动
- 【每周至少一篇 160819】最大子序列和问题的四种求法_Java