451B - Sort the Array
来源:互联网 发布:php 修改文件名 编辑:程序博客网 时间:2024/05/21 17:44
这道题的意识是给你一个整形数组,含有很多数字,然后让你通过讲中间的某一个字串颠倒过来,让他成为不下降的数组。其实这题都是特简单的,只要你找到一个不满足上升的字串,然后反过来,直接break,最后判断是不是非下降排列即可。
#include<iostream>using namespace std;#include<cstring>#include<stdio.h>int a[100005];int main(){ int N; int i,j,k; while(cin>>N) { k=0;//标记 int i1=0,j1=0; for(i=0;i<N;i++) scanf("%d",&a[i]); for(i=0;i<N-1;i++) { if(a[i]>a[i+1]) { if(!k) { k=1; i1=i; } } else if(k) { j1=i; break; } } if(k&&j1==0)j1=N-1; // cout<<i1<<" "<<j1<<endl; k=j1; for(i=i1;i<=(j1+i1)/2;i++,k--) { j=a[i]; a[i]=a[k]; a[k]=j; } k=0; for(i=0;i<N-1;i++) if(a[i]>a[i+1]) { k=1; break; } // for(i=0;i<N;i++) // cout<<a[i]<<" "; if(k)cout<<"no"<<endl; else { cout<<"yes"<<endl; cout<<(i1+1)<<" "<<(j1+1)<<endl; } } return 0;}
0 0
- 451 B. Sort the Array
- 451B - Sort the Array
- B - Sort the Array
- B. Sort the Array
- Codeforces 451B Sort the Array
- Codeforces 451B Sort the Array(水题)
- codeforce 451B Sort the Array
- Codeforces 451 B. Sort the Array
- CodeForces 451B Sort the Array
- CodeForces 451B. Sort the Array
- codeforces 451B Sort the Array
- codeforce-B. Sort the Array
- CodeForces 451B Sort the Array(排序,逆序)
- [Codeforces 451B] Sort the Array (实现)
- CodeForces - 451B Sort the Array 简单模拟
- CF 258B. Sort the Array
- Codeforces #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2) 2B Sort the Array
- 学习博客
- [c#]分析器错误消息: 发现不明确的匹配。
- 激乐人心.内嵌中字
- line-height绝对值和相对值的区别
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- 451B - Sort the Array
- 修改ArrayList
- Android开发框架androidannotations使用初始
- 4.4临时文件
- win8下安装mac10.8.4懒人版双系统教程
- lca倍增算法
- 【原创】纪念写技术博客第十年
- XML中转义字符(Android可用)
- jQuery学习简要笔记