http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=52107

给出一个数列,问截取哪一部分连续子列进行翻转可以使整个数列升序排列,

如果有这样的字串输出yes和截取位置,没有输出no

就是先记录原始位置进行排序,之后一旦发现一个元素排序后更改了位置那它就被翻转过。

完全逆序排列应该是排序后原先的位置依次减1,这样得到被翻转的前后位置。

之后继续扫描,如果还有位置不对的,说明翻转一段不能完成,输出no

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define LEN 100005
 4 typedef struct point{
 5     int a, p;
 6     bool operator < (const point& p) const{
 7         return a < p.a;
 8     }
 9 }point;
10 point arr[LEN];
11
12 int main(){
13     int n;
14     while(~scanf("%d", &n)){
15         memset(arr, 0, sizeof(arr));
16         for(int i = 1; i <= n; i++){
17             scanf("%d", &arr[i].a);
18             arr[i].p = i;
19         }
20         sort(arr+1, arr+1+n);
21         int lpos = 1, rpos = 1;
22         bool f = true;
23         for(int i = 1; i <= n; i++)
24             if(arr[i].p != i){
25                 lpos = i;
26                 rpos = i;
27                 break;
28             }
29         for(int i = lpos+1; i <= n; i++){
30             if(arr[i].p == arr[i-1].p-1) rpos = i;
31             else break;
32         }
33         for(int i = rpos+1; i <= n; i++)
34             if(arr[i].p != i){
35                 f = false;
36                 break;
37             }
38         if(f == false) puts("no");
39         else{
40             puts("yes");
41             printf("%d %d\n", lpos, rpos);
42         }
43     }
44     return 0;
45 }

转载于:https://www.cnblogs.com/miaowTracy/p/5385172.html

【模拟】【codeforces】451B Sort the Array相关推荐

  1. [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序

    11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...

  2. (周日赛)Sort the Array

    题意:一段数字,逆置其中两个使其递增 Description Being a programmer, you like arrays a lot. For your birthday, your fr ...

  3. CodeForces 1514A Perfectly Imperfect Array

    CodeForces 1514A Perfectly Imperfect Array 题意: 给你n个数,是否存在一个数不是平方数 题解: 先开方,转int,判断是否等于平方 代码: #include ...

  4. codeforces 258div2 B Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...

  5. CodeForces 360A - Levko and Array Recovery (模拟)

    题目地址:点击打开链接 思路: 维护每个数的上下界,先按照操作倒着求一遍,可以得到每个数的上界,再按操作正着验证一遍是否能够满足.如果都能满足的话输出上界即可. 代码: #include<ios ...

  6. CodeForces - Insertion Sort(打表找规律)

    题目链接:http://codeforces.com/gym/101955/problem/C Time limit:6.0 s Memory limit:1024 MB Problem Descri ...

  7. CodeForces 86 D Powerful array 莫队

    Powerful array 题意:求区间[l, r] 内的数的出现次数的平方 * 该数字. 题解:莫队离线操作, 然后加减位置的时候直接修改答案就好了. 这个题目中发现了一个很神奇的事情,本来数组开 ...

  8. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

  9. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C 1 /* 2 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 3 模拟题:蛮恶心的 ...

最新文章

  1. 干货丨从基础知识到实际应用,一文了解「机器学习非凸优化技术」
  2. OFDM专题之理解原理图(暂不包含用IFFT以及FFT的原理图形式)
  3. 从程序员到项目经理(十一):每个人都是管理者
  4. kibana安装与Kibana server is not ready yet
  5. php单下划线的函数,基于PHP函数的操作方法
  6. ffmpeg 0.8.7在windows环境mingw环境的编译
  7. I/O多路复用之epoll实战
  8. tomcat 的 catalina.out 日志文件,禁用
  9. 走进社交网络 二期功能完成
  10. SSH框架的详细介绍
  11. 软工网络15团队作业8——Beta阶段冲刺合集
  12. Block will be retained by an object strongly retained by the captured object
  13. 程序龙的密码(递归算法)
  14. pytorch第06天 图片分类器
  15. redux-thunk-基本使用
  16. Swift - 判等
  17. NumPy 基础教程
  18. 事业单位笔试:《综合知识》大纲
  19. 《windows 程序设计》中的翻译错误----学习笔记
  20. php 获取服务器进程数,PHP 获取linux服务器性能CPU、内存、硬盘、进程等使用率...

热门文章

  1. 修改js文件需要重启服务器,关于Node.js中频繁修改代码重启服务器的问题
  2. android复制链接到粘贴板,Android复制粘贴到剪贴板
  3. 中兴高达和中兴啥关系_打通信息孤岛!中兴高达一体化通信指挥平台
  4. Python ln_Python入门教程(三):史上最全的Numpy计算函数总结,建议收藏!
  5. android activity启动流程_1307页!一线大厂Android面试全套真题解析!
  6. miniUI怎么显示HTML显示整数,MINIUI后台获取数据
  7. rabbitmq实战指南_RabbitMQ之脑裂
  8. .net 导出excel_java导出excel(easypoi)
  9. 记录一下Pycharm习惯的快捷键
  10. yolov5检测完不显示框和标注