题意:找出一段逆序!

预存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. jQuery学习-事件之绑定事件(二)

    在上一篇<jQuery学习-事件之绑定事件(一)>我们了解了jQuery的add方法,今天我们来学习下dispatch方法: dispatch: function( event ) {   ...

  2. android4.0 HttpClient 以后不能在主线程发起网络请求

    android4.0以后不能在主线程发起网络请求,该异步网络请求. new Thread(new Runnable() { @Override public void run() { // TODO ...

  3. C语言的本质(5)——类型转换的本质与处理

    数据类型转换的方式 C 语言中的数据类型转换可分为隐式转换和显式转换两种. 隐式转换 隐式转换也可称作为自动转换,它经常以以下几种形式发生: 1.在计算一个同时出现多种数据类型的表达式时,将所有数据类 ...

  4. MFC CWnd仿按钮

    CBtn::CBtn() { RegisterWndClass(); } bool CBtn::RegisterWndClass(void) { WNDCLASS n; HINSTANCE hInst ...

  5. The MySQL C API 编程实例

    在网上找了一些MYSQL C API编程的文章,看了后认为还是写的不够充分,依据自己经验写了这篇<The MySQL C API 编程实例>,希望对须要调用到MYSQL的C的API的朋友有 ...

  6. jquery动态连接节点

    <1> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  7. Linux下patch打补丁命令

    此命令用于为特定软件包打补丁,他使用diff命令对源文件进行操作. 基本命令语法: patch [-R] {-p(n)} [--dry-run] < patch_file_name p:为pat ...

  8. PHP中cURL错误号对照[转]

    PHP cURL curl_errno 在php程序编写中,使用curl函数库的几率还是挺高的,如curl_init().curl_setopt().curl_exec().curl_errno()等 ...

  9. ora-14550问题解决

    select a.sid, a.serial#, a.paddr, 'alter system kill session ''' || a.sid || ',' || a.serial# || ''' ...

  10. phpStrom添加插件:php文档生成(phpDocumentor)

    1. 依次打开:Files => Settings => External Tools => +(add) 2. 填写信息:name:phpDoc; group:PHP插件; des ...