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

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

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

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long INT;
const int maxn = +;
INT que[maxn],que2[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ;i <= n;++i)
{
scanf("%lld",&que[i]);
que2[i] = que[i];
}
sort(que+,que+n+);
int l = ;
for(;l < n;++l)
if(que[l] == que[l+])
break;
if(l < n)
{
printf("no\n");
continue;
}
int s = ,e = n;
while(s <= n && que[s] == que2[s]) s++;
if(s > n)
{
printf("yes\n1 1\n");
continue;
}
while(e >= && que[e] == que2[e]) e--;
int x = s,y = e;
while(s <= y && que[s] == que2[e]) s++,e--;
printf(s > y? "yes\n%d %d\n":"no\n",x,y);
}
return ;
}

codeforces 258div2 B Sort the Array的更多相关文章

  1. 【Codeforces 258B】 Sort the Array

    [题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...

  2. Codeforces Round #258 (Div. 2) . Sort the Array 贪心

    B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...

  3. Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

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

  4. Codeforces Round #258 (Div. 2)——B. Sort the Array

    B. Sort the Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  6. [codeforces 360]A. Levko and Array Recovery

    [codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...

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

  8. [LeetCode] 912. Sort an Array 数组排序

    Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1] Outp ...

  9. LeetCode 912. 排序数组(Sort an Array) 43

    912. 排序数组 912. Sort an Array 题目描述 每日一算法2019/6/15Day 43LeetCode912. Sort an Array

随机推荐

  1. IOS动态判断UITextField是否输入为手机号

    现在使用的app大部分都用到手机号注册,很多app注册的时候会判断手机号,可以根据当前输入文本来判断“获取验证码”的按钮是否可用 判断输入文本是通过UITextField的代理的 -(BOOL)tex ...

  2. GDI+中发生一般性错误的解决办法(转帖)

    今天在开发.net引用程序中,需要System.Drawing.Image.Save 创建图片,debug的时候程序一切正常,可是发布到IIS后缺提示出现“GDI+中发生一般性错误”的异常.于是开始“ ...

  3. JSP/SERVLET入门教程--Servlet 使用入门

    现在的JSP书籍有的是直接讲述JSP的使用,然后再讲解SERVERLET的使用;也有书籍是先讲述SERVERLET的使用,然后讲解JSP使用.个人认为第二种相对好一些,至于原因大家可以在学习体会到!所 ...

  4. oracle 的安装脚本

    ==[root@oracle ~]# cat 1.preusers.sh ==#!/bin/bash#Purpose:Create 3 groups named 'oinstall','dba','o ...

  5. Maven 初学(一)基本概念

    Pom中有三个主要元素 Groupid,artifactid,version goupid 是一个组织唯一的标识  例如 com.ibm.www artifactid  是一个工程呢ID        ...

  6. 问问题_Java一次导出百万条数据生成excel(web操作)

    需求:在web页面操作,一次导出百万条数据并生成excel 分析: 1.异步生成Excel,非实时,完成后使用某种方式通知用户 2.生成多个excel文件,并打包成zip文件,因为一个excel容纳不 ...

  7. Java-小数点控制

    package 运算及类型转换类; import java.text.DecimalFormat; public class 控制小数点类 { public static double decimal ...

  8. 【CodeForces 557B】Pasha and Tea

    题 题意 总共有 w 克蛋糕,2n 个盘子,第 i 个盘子容量为 ai ,n 个女孩和 n 个男孩,男孩得到的是女孩得到的蛋糕的两倍,求他们得到蛋糕的最大值. 分析 把盘子从小到大排序,然后 女生得到 ...

  9. nmap常用命令

    1) 获取远程主机的系统类型及开放端口 nmap -sS -P0 -sV -O <target> 这里的 < target > 可以是单一 IP, 或主机名,或域名,或子网 - ...

  10. php中图片文件的导入,上传与下载

    ---------------------------------------------图片的导入-------------------------------------------------- ...