题意:找出一段逆序!

预存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. linux----ln

    1.格式 ln source_file_path target_file_path 2.执行ln 命令的用户要对source_file_path有写权限,才可以创建软连接. 3.souce_file这 ...

  2. 论山寨手机与Android 【11】移动网络规范的合纵连横

    上一章我们讨论了SmartPhone BP部分的硬件系统,接下去我们将讨论SmartPhone BP部分的软件系统.所谓BP,指的是基带处理器(Baseband Processor),又称为通讯处理器 ...

  3. heap creation

    There two methods to construct a heap from a unordered set of array. If a array has size n, it can b ...

  4. C# 使用XmlDocument类对XML文档进行操作

    原创地址:http://www.cnblogs.com/jfzhu/archive/2012/11/19/2778098.html 转载请注明出处 W3C制定了XML DOM标准.很多编程语言中多提供 ...

  5. 【翻译自mos文章】改变数据库用户sysman(该用户是DB Control Repository 的schema)password的方法

    改变数据库用户sysman(该用户是DB Control Repository 的schema)password的方法 參考原文: How To Change the Password of the ...

  6. POJ 2774 Long Long Message&&HDU 1403 Longest Common Substring&&COJ 1203

    后缀数组的买1送2题... HDU的那题数据实在是太水了,后来才发现在COJ和POJ上都是WA..原因在一点:在建立sa数组的时候里面的n应该是字符串长度+1....不懂可以去看罗大神的论文... 就 ...

  7. Codeforces 475C Kamal-ol-molk&#39;s Painting 模拟

    主题链接:点击打开链接 意甲冠军:特定n*m矩阵 X代表色 .代表无色 随着x*y形刷子去涂色. 刷子每次能够→或↓移动随意步. 若可以染出给定的矩阵,则输出最小的刷子的面积 若不能输出-1 思路: ...

  8. 联想A208T ROOT

    前几天,一直陪伴我的海信T89电池挂掉...胀胀的肚子...真可怜 一时之间找不到配套的电池,就借了个手机先用着,就是这 联想A208T ROOT... 话说的配置一般般,勉强够我这样的不怎么玩手机的 ...

  9. SQL Server执行计划那些事儿(2)——查找和扫描

    接下来的文章是记录自己曾经的盲点,同时也透漏了自己的发展历程(可能发展也算不上,只能说是瞎混).当然,一些盲点也在工作和探究过程中慢慢有些眉目,现在也愿意发扬博客园的奉献精神,拿出来和大家分享一下. ...

  10. js 全局变量

    使用cookies可以设置全局变量 ,由于每次刷新变量都会为初始值,cookies可以作为全局变量的容器