ACM训练二B题
发布日期:2021-08-21 12:06:03 浏览次数:2 分类:技术文章

本文共 2150 字,大约阅读时间需要 7 分钟。

这是比赛后打的题目,思路很清晰:申明一个结构体,将输入的数复制在这个结构体数组中,排序后比对下标,找到变动的首下标和尾下标,再看这段是否逆序了。

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of ndistinct integers.

Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array a (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.

The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109).

Output

Print "yes" or "no" (without quotes), depending on the answer.

If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.

Sample Input

Input
3 3 2 1
Output
yes 1 3
Input
4 2 1 3 4
Output
yes 1 2
Input
4 3 1 2 4
Output
no
Input
2 1 2
Output
yes 1 1
#include 
#include
using namespace std;int a[100017];struct NUM{ int x,id;}b[100017];bool cmp(NUM x,NUM y){ return x.x < y.x;}int main(){ int n; cin >> n; for(int i = 1;i <= n;i++) { cin >> a[i]; b[i].x = a[i]; b[i].id = i; } sort(b+1,b+n+1,cmp); int i,j; for(i = 1;i <= n;i++) { if(b[i].id != i) { break; } } if(i == n+1) { cout << "yes" << endl << "1 1" << endl; return 0; } for(j = n;j > 0;j--) { if(b[j].id != j) { break; } } int tt = i;int t = j; while(i<=j) { if(a[i] != b[t--].x) { break; } i++; } if(i == j+1) { cout << "yes" << endl << tt << " " << j << endl; } else { cout << "no" << endl; } return 0;}

 

转载于:https://www.cnblogs.com/hhhhhhhhhhhhhhhhhhhhhhhhhhh/p/3874382.html

转载地址:https://blog.csdn.net/weixin_33717298/article/details/93186828 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Python中super的应用
下一篇:多用户密码文件读取加密口令登陆

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年03月24日 03时56分03秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

class选择器第一个_CSS -- 序列选择器 2019-04-21
樊登读书分享ppt_运营管理部读书会感悟分享——观看樊登读书之善战者说:孙子兵法与取胜法则十二讲视频... 2019-04-21
okhttp3图片压缩上传_使用 python 压缩 png 图片,高达 80% 压缩率,肉眼无差异!... 2019-04-21
上海税前12000税后多少_新同事和老板谈的到手工资,带你一键计算总工资是多少~... 2019-04-21
python流行的爬虫框架_不知道Python爬虫?这篇文章丢给他(内含框架结构) 2019-04-21
mysql查看用户权限r_MYSQL用户权限相干管理 2019-04-21
php 数据库 mysql导航菜单_【php】php操作MySQL数据库 2019-04-21
postgres 显示变量_postgresql SQL语句变量的使用说明 2019-04-21
vue下拉框动态数据绑定_vue开端 -- 做个工匠 - 1 数据绑定 以及 指令 2019-04-21
python中print又可将数据写入文件_如何使用python将数据写入txt文件 2019-04-21
python写linux命令_Python写的系统常用命令 2019-04-21
python减法怎么办_为什么减法比Python中的加法快? 2019-04-21
python在金融领域的前景_让我们在金融技术领域学习Python~~,一,起来,科技领域,的,python,吧... 2019-04-21
cesium 局部加载_Cesium中部分高度的讲解 2019-04-21
mysql 锁的架构_总结Mysql中的锁 2019-04-21
mysql直接拷贝ibd文件_Linux下使用ibd文件实现MySQL的数据导入和使用 2019-04-21
python迭代器两个基本方法可供参考_Python迭代器与生成器基本用法分析 2019-04-21
java gui可视化小程序_java控制台实现可视化日历小程序 2019-04-21
mysql安装ZIP存档什么意思_mysql压缩包(.zip)安装 2019-04-21
java编译后产生_Java编译后产生class文件的命名规则 2019-04-21