题目链接:http://codeforces.com/contest/451/problem/B

解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列。

我的做法有点不一样,我是将原来的序列先按照升序排好序,然后分别从头和尾开始扫,找到跟原来的数组不一样的子序列的区间,然后判断这个区间是不是原来的区间翻转而来。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef long long INT;
 7 const int maxn = 100000+5;
 8 INT que[maxn],que2[maxn];
 9 int main()
10 {
11     int n;
12     while(scanf("%d",&n)!=EOF)
13     {
14         for(int i = 1;i <= n;++i)
15         {
16             scanf("%lld",&que[i]);
17             que2[i] = que[i];
18         }
19         sort(que+1,que+n+1);
20         int l = 1;
21         for(;l < n;++l)
22         if(que[l] == que[l+1])
23         break;
24         if(l < n)
25         {
26             printf("no\n");
27             continue;
28         }
29         int s = 1,e = n;
30         while(s <= n && que[s] == que2[s]) s++;
31         if(s > n)
32         {
33             printf("yes\n1 1\n");
34             continue;
35         }
36         while(e >= 1 && que[e] == que2[e]) e--;
37         int x = s,y = e;
38         while(s <= y && que[s] == que2[e]) s++,e--;
39         printf(s > y? "yes\n%d %d\n":"no\n",x,y);
40     }
41     return 0;
42 }

View Code

转载于:https://www.cnblogs.com/xiaxiaosheng/p/3868091.html

codeforces 258div2 B Sort the Array相关推荐

  1. 【模拟】【codeforces】451B Sort the Array

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=52107 给出一个数列,问截取哪一部分连续子列进行翻转可以使整个数列升序排列, ...

  2. [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. 这道题 ...

  3. (周日赛)Sort the Array

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

  4. Codeforces Round 722C:Destroying Array(离线)

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces 362C. Insertion Sort

    DP预处理+枚举逆序对 C. Insertion Sort time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. [题解]Codeforces Round #519 - B. Lost Array

    [题目] B. Lost Array [描述] Bajtek有一个数组x[0],x[1],...,x[k-1]但被搞丢了,但他知道另一个n+1长的数组a,有a[0]=0,对i=1,2,...,n.由此 ...

  7. 【CodeForces - 361D】Levko and Array (二分,dp)

    题干: Levko has an array that consists of integers: a1, a2, ... , an. But he doesn't like this array a ...

  8. Sort the Array

    1 /* 2 思路: 3 找到单调下降串的起始位置[l, r] 4 如果左边 0...l-1中的最大值 > l...r中的最小值 或者 5 r+1...n中的最小值 < l...r中的最大 ...

  9. codeforces 361 D. Levko and Array(dp+二分)

    题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之 ...

最新文章

  1. python培训班那家好-Python培训机构去哪好
  2. C++ 多态实现机制
  3. 1081. Rational Sum (20) -最大公约数
  4. mitmproxy抓包 | Python双篡改假请求实战(六)
  5. foreach 和 for 循环的区别
  6. c++多边形扫描线填充算法_基于MATLAB的道格拉斯普克算法递归实现
  7. 全面进军javascript!
  8. 1053: [HAOI2007]反素数ant
  9. java集中常见的算法讲解
  10. 程序员 需要什么ssd固态_什么是固态驱动器(SSD),我需要一个吗?
  11. macOS调整分辨率与HiDPI
  12. 正则表达式校验手机号
  13. 全球及中国粮食加工行业产量需求规模与投资产值预测报告2022版
  14. windows10下使用DNW下载
  15. M1 Mac 安装iPad、iPhone App
  16. 为什么自来水按立方米收费?
  17. ffmpeg mp4 mp3 wav flac webm aac ac3 ogg格式转换
  18. 阅读java源代码的阅读器_TXT小说阅读器java代码
  19. 上市企业高管背景研究——男、女性高管数据
  20. 思维导图 | XMind 8 Update 8 Pro 自动破解版

热门文章

  1. 最新pvz服务器补偿码,阴阳师:补偿来了!大量活动导致服务器崩溃,现已修复且下发补偿...
  2. linux制作光盘镜像文件
  3. 二分图带权最大匹配费用流_简单理解二分图与匈牙利算法
  4. 客观评价golang的优缺点
  5. python str转json_Python中如何将一个字符串转换为json格式呢?
  6. 【自我救赎--牛客网Top101 4天刷题计划】 第三天 渐入佳境
  7. 【数据结构的魅力】004.堆、前缀树、桶排序、排序算法总结
  8. 每天Leetcode 刷题 初级算法篇-缺失数字
  9. html5 音频事件,HTML5中视频和音频核心事件的相关研究
  10. 配置多台机器SSH相互通信信任