题意:找出一段逆序!

预存a[]数组到b[]数组。将b排序,然后前后找不同找到区间[l,r],然后推断[l,r]是否逆序就能够了!。当然还得特判本身就是顺序的!!

AC代码例如以下:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std; int a[100005],b[100005]; int main()
{
int n;
int i;
while(cin>>n)
{
memset(a,0,sizeof a);
memset(b,0,sizeof b);
for(i=0;i<n;i++)
{cin>>a[i];
b[i]=a[i];}
sort(b,b+n);
int flag1=1;
for(i=0;i<n;i++)
{
if(a[i]!=b[i])
{flag1=0;break;}
}
if(flag1)
{
cout<<"yes"<<endl<<"1"<<" "<<"1"<<endl;
continue;
}
int flag=0;
int l=0,r=n-1;
for(i=0;i<n;i++)
{
if(a[i]!=b[i])
{
l=i;
break;
}
}
for(i=n-1;i>=0;i--)
{
if(a[i]!=b[i])
{
r=i;
break;
}
}
for(i=l+1;i<=r;i++)
{
if(a[i]>a[i-1])
{flag=1;break;}
}
if(flag)
cout<<"no"<<endl;
else cout<<"yes"<<endl<<l+1<<" "<<r+1<<endl;
}
return 0;
}

CF Codeforces Round #258 (Div. 2) B (451B)的更多相关文章

  1. Codeforces Round #258 (Div. 2) 小结

    A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...

  2. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  3. CF Codeforces Round #231 (Div. 2)

    http://codeforces.com/contest/394 话说这次CF做的超级不爽,A题一开始交过了,我就没再管,B题还没看完呢,就死困死困的,后来觉得B题枚举一下估计能行,当时是觉得可以从 ...

  4. [cf]Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

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

    题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...

  6. Codeforces Round #258 (Div. 2) E. Devu and Flowers 容斥

    E. Devu and Flowers 题目连接: http://codeforces.com/contest/451/problem/E Description Devu wants to deco ...

  7. Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题

    D. Count Good Substrings 题目连接: http://codeforces.com/contest/451/problem/D Description We call a str ...

  8. Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game 水题

    C. Predict Outcome of the Game 题目连接: http://codeforces.com/contest/451/problem/C Description There a ...

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

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

随机推荐

  1. mysql中timestamp,datetime,int类型的区别与优劣

    转载请注明来自 souldak,微博: @evagle 以下内容 整合筛选自互联网: int 1. 占用4个字节 2. 建立索引之后,查询速度快 3. 条件范围搜索可以使用使用between 4. 不 ...

  2. css案例学习之并集选择器

    代码 <html> <head> <title>并集选择器</title> <style type="text/css"> ...

  3. 第52周四ApplicationContext

    ApplicationContext的中文意思是"应用前后关系"应用上下文即容器,它继承自BeanFactory接口,除了包含BeanFactory的所有功能之外,在国际化支持.资 ...

  4. VC维度

    ​由vc bound可以知道: $P(\exists h\in H~s.t~|E_{in}(h)-E_{out}(h)|>\epsilon)\\ \leq 4M_H(2N)exp(-\frac{ ...

  5. ceph for openstack快速部署实施

    for el6 即centos6 1,添加ceph 官方yum源 [root@ruiy ~]# cat /etc/yum.repos.d/ceph.repo[ceph-noarch]name=Ceph ...

  6. 实现多文件上传在iOS开发中

    该功能实现了实现多文件上传在iOS开发中,喜欢的朋友可以研究一下吧. NSURL* url = [NSURL URLWithString:@"xxx"]; ASIFormDataR ...

  7. POJ2528线段树基础

    開始就直接用延迟标记搞了下.最后发现内存肯定会爆了.数据太大了. 问了瓜神,原来应该用离散化来做这题,详细见凝视 #include <cstdio> #include <cstrin ...

  8. jQuery源码笔记——数据缓存

    数据缓存是为了解决内存泄露,他的原理是,当我们将数据存储到一个对象上面,实际上是将所有的数据存到一个单独的数据对象里,而这个对象只提供一个接口,这个接口可以访问自己存在数据对象里自己的数据. 这是一个 ...

  9. web基础-web工作原理,http协议,浏览器缓存

    1,web工作原理 2,http协议 3,浏览器缓存 4,cookie和session -------------------------------------------------------- ...

  10. html系列教程--embed fieldset legend figure figurecaption

    <embed> 标签:定义嵌入的内容 <embed src="" type="" /> embed属性: 1.src:嵌入内容地址 2. ...