CF Codeforces Round #258 (Div. 2) B (451B)
题意:找出一段逆序!
预存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)的更多相关文章
- Codeforces Round #258 (Div. 2) 小结
A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...
- Codeforces Round #258 (Div. 2)[ABCD]
Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...
- CF Codeforces Round #231 (Div. 2)
http://codeforces.com/contest/394 话说这次CF做的超级不爽,A题一开始交过了,我就没再管,B题还没看完呢,就死困死困的,后来觉得B题枚举一下估计能行,当时是觉得可以从 ...
- [cf]Codeforces Round #784(Div 4)
由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
随机推荐
- 给ecshop后台增加管理功能页面
给ecshop后台增加管理功能页面 比如我们增加一个统计报表叫做 物流费用统计报表 放在后台“报表统计”栏目中 具体操作步骤: 第一步,我们要添加一个菜单到后台,然后设置语言项,最后设置权限,这样,后 ...
- uvalive 6657 GCD XOR
//感觉太长时间没做题 好多基本的能力都丧失了(>_<) 首先大概是这样的,因为gcd(a,b)=c,所以a,b都是c的倍数,所以我们依次枚举a的值为2c 3c 4c......,a xo ...
- centos安装qt开发环境
- xshell使用命令总结
这个工具主要是链接linux 并且可以从linux上面下载文件到本地 还有上传本地文件到linux上面 下载首先需要压缩打包命令为: tar -cf am_mailer.tar * sz am_mai ...
- hdu 3068 最长回文(manachar求最长回文子串)
题目连接:hdu 3068 最长回文 解题思路:通过manachar算法求最长回文子串,如果用遍历的话绝对超时. #include <stdio.h> #include <strin ...
- JavaScript 的DOM操作
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. Windows 对象操作 ...
- Java基础笔记-面向对象2
构造函数:(当类中没有定义构造函数时,系统会默认给该类加入一个空参数的构造函数) 格式: class Person { Person(){} //空参数 } 1.函数名与类名相同, 2,不定义返回值类 ...
- SQL事务与并发
1.Transaction(事务)是什么: 事务是作为单一工作单元而执行的一系列操作.包括增删查改. 2.事务的种类: 事务分为显示事务和隐式事务: 隐式事务:就是平常我们使用每一条sql 语句就是一 ...
- php,ajax登陆退出
利用ajax可以做到页面无刷新登陆. 运行效果 目录结构 site/ css/ images/ js/ site/css/bootstrap.css(bootstrap样式表) site/js/boo ...
- Spring MVC JSON 实现JsonSerializer Date类型转换
转载至:http://blog.csdn.net/lantianzhange/article/details/40920933 在Spring MVC中存在两大类的类型转换,一类是Json,一个是Sp ...