codeforces 258div2 B Sort the Array
题目链接: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的更多相关文章
- 【Codeforces 258B】 Sort the Array
[题目链接] http://codeforces.com/contest/451/problem/B [算法] 模拟 在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即 ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
题目链接:http://codeforces.com/contest/451/problem/B --------------------------------------------------- ...
- 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 ...
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- [codeforces 360]A. Levko and Array Recovery
[codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...
- [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. 这道题 ...
- [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 ...
- LeetCode 912. 排序数组(Sort an Array) 43
912. 排序数组 912. Sort an Array 题目描述 每日一算法2019/6/15Day 43LeetCode912. Sort an Array
随机推荐
- 开源分布式实时计算引擎 Iveely Computing 之 安装部署(2)
在Github中下载代码和二进制程序中,您都会看到一个bin\iveely computing目录,里面即是Iveely Computing的运行库. 以前总是有 ...
- jqurey 遍历 div内的所有input单选复选按钮并判断是否选中及Attr(checked)无效的解决
关于页面前面标签 <ul> @{ foreach (var item in vote) { if (!string.IsNullOrEmpty(item.Img)) { <li cl ...
- 23.C#Queryable的扩展方法(十二章12.1-12.2)
今天要写的知识还真心有点绕呢,对于第一节的内容,其实是把原先在内存中的数据源,换成了从数据库中提取出来的数据.从代码的使用方式上是一样的,直接跳过,来看看IEnumerable和IQueryable的 ...
- c# 6.0新特性(一)
写在前面 接近年底了,基本上没什么活了,就学点新东西,就想着了解下c# 6.0的新特性.在code project上看到了一篇不错的文章,就准备翻译一下,顺便照着学习学习.废话不多说,直奔主题. 原文 ...
- Bootstrap3.0学习第二十三轮(JavaScript插件——警告框)
详情请查看http://aehyok.com/Blog/Detail/29.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 阿里百川IIMSDK-- 加好友,获取好友
加好友, 其实就是跟发消息一样 获取好友列表 同步好友列表 SDK内部默认会在每次登陆成功后与服务端同步好友列表,开发者可以通过设置disableAutoRequestAllContacts来禁用这个 ...
- Html-Css-div标签嵌套浮动div标签时无法撑开外部div的解决
当DIV1里面嵌套有一个DIV2,当DIV2设置了浮动,那么DIV1是无法被撑开的 当DIV1里面嵌套有一个DIV2,当DIV2设置了浮动,那么DIV1是无法被撑开的,也就是说DIV2在这里相当于浮在 ...
- Java基础-内部类
在Java中,可以将一个类定义在另一个类里面或者一个方法里面,这样的类称为内部类.广泛意义上的内部类一般来说包括这四种:成员内部类.局部内部类.匿名内部类和静态内部类. 下面就先来了解一下这四种内部类 ...
- HTTP各个状态返回值
转载来自于:http://desert3.iteye.com/blog/1136548 502 Bad Gateway:tomcat没有启动起来 504 Gateway Time-out: nginx ...
- PowerDesigner导出的sql中去掉双引号,主要用于Oracle
如题,这些双引号对于Oracle建表实在是糟糕透了: 解决方法: (转载,作者的百度已经挂了,无法放上链接,自私一把,以前的Oracle项目不见了,无法展示) 1.去掉Oracle生成的SQL创建语句 ...