B题 Sort the Array
题目大意:
判断能否通过一次倒置,使序列变为一个递增序列
如果可以,输出倒置那一段的起始点和终点的位置;
题目链接:http://codeforces.com/problemset/problem/451/B
我自己的做法是用一个数组b保存原数组中小于后一个点的点的下标。
如果b数组中后一个数比前一个数大了超过一,说明有2段递减序列,不成立。
如果均后一个比前一个大1,那么在判断倒置前起始的位置和它倒置后的下一个位置是否递增进行判断,在进行倒置前结束的位置和它倒置后的上一个位置是否递增进行判断
均成立,输出两个位置
#include<iostream>
#include<cstdio>
using namespace std;
#define N 100100
int a[N],b[N];
int cnt;
int main()
{
int n,flag; while(scanf("%d",&n)!=EOF){
flag=;cnt=; for(int i=;i<n;i++) b[i]=-;
for(int i=;i<n;i++) cin>>a[i];
for(int i=;i<=n-;i++){
if(a[i]>a[i+]) b[cnt++]=i;
}
if(cnt>)
{
b[cnt]=b[cnt-]+;
cnt++;
} for(int i=;i<cnt-;i++){
//cout<<b[i]<<endl;
if(b[i+]-b[i]!=)
{
flag=;
break;
}
}
if(b[]==-) {cout<<"yes"<<endl<<<<' '<<<<endl;continue;} if(flag==)
{
if(b[cnt-]<n-) {if(a[b[]]>a[b[cnt-]+])flag=;}
if(b[]>){if(a[b[cnt-]]<a[b[]-]) flag=;}
} if(flag==)cout<<"no"<<endl;
else{
cout<<"yes"<<endl<<b[]+<<' '<<b[cnt-]+<<endl;
}
} return ;
}
B题 Sort the Array的更多相关文章
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
题目链接:http://codeforces.com/contest/451/problem/B --------------------------------------------------- ...
- [LeetCode] 912. Sort an Array 数组排序
Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1] Outp ...
- [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序
11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
- Codeforces Round #258 (Div. 2)——B. Sort the Array
B. Sort the Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- LeetCode 912. 排序数组(Sort an Array) 43
912. 排序数组 912. Sort an Array 题目描述 每日一算法2019/6/15Day 43LeetCode912. Sort an Array
- Minimum number of swaps required to sort an array
https://www.hackerrank.com/challenges/minimum-swaps-2/problem Minimum Swaps II You are given an unor ...
- 【leetcode】912. Sort an Array
题目如下: Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1 ...
随机推荐
- nginx缓存配置及开启gzip压缩
阅读目录 一:nginx缓存配置 二:nginx开启gzip 回到顶部 一:nginx缓存配置 在前一篇文章,我们理解过http缓存相关的知识点, 请看这篇文章. 今天我们来学习下使用nginx服务来 ...
- 分享几个自己喜欢的前端UI框架
http://www.layui.com/ http://element-cn.eleme.io/#/zh-CN/component/installation
- asp.net 线程批量导入数据,ajax获取执行状态
最近做了一个批量导入功能,长时间运行,没个反馈状态,很容易让人看了心急,产生各种臆想!为了解决心里障碍,写了这么个功能. 通过线程执行导入,并把正在执行的状态存入session,既共享执行状态,通过a ...
- arttemplate模板引擎有假数据返回数据多层内嵌的渲染方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- php 缓存工具类 实现网页缓存
php 缓存工具类 实现网页缓存 php程序在抵抗大流量访问的时候动态网站往往都是难以招架,所以要引入缓存机制,一般情况下有两种类型缓存 一.文件缓存 二.数据查询结果缓存,使用内存来实现高速缓存 本 ...
- Oracle Storage in Action : 删除物理数据文件
ALTER TABLESPACE XH_DM DROP DATAFILE 'F:\DEV\ORACLE-DATA\ORCL\XH_DM_1.DBF'; SQL> ALTER TABLESPACE ...
- Windows各个文件夹介绍
windows文件介绍 总结 ├WINDOWS │ ├-system32(存放Windows的系统文件和硬件驱动程序) │ │ ├-config(用户配置信息和密码信息) │ │ │ └-system ...
- 数据库管理系统X
大部分DBMS提供数据定义语言DDL(Data Definition Language)和数据操作语言DML(Data Manipulation Language),供用户定义数据库的模式结构与权限约 ...
- powerDesigner 一些设置
常用设置 table中需要显示的内容 --------------------------------------------------------------------------------- ...
- uva1610 Party Games
细节值得注意 注意vector<string>是可以直接sort的! #include <iostream> #include <string> #include ...