【Codeforces 258B】 Sort the Array
【题目链接】
http://codeforces.com/contest/451/problem/B
【算法】
模拟
在序列中找到一段单调递增的子序列,将这段序列反转,然后判断序列是否变得单调递增,即可
【代码】
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ; int i,n,l,r;
bool flag;
int a[MAXN]; int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%d",&a[i]);
l = r = ;
flag = false;
for (i = ; i <= n; i++)
{
if (a[i] < a[i-])
{
if (!flag)
{
l = i - ;
r = i;
}
else r++;
flag = true;
} else if (flag) break;
}
reverse(a+l,a+r+);
for (i = ; i <= n; i++)
{
if (a[i] < a[i-])
{
printf("no\n");
return ;
}
}
printf("yes\n");
printf("%d %d\n",l,r); return ; }
【Codeforces 258B】 Sort the Array的更多相关文章
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 719E】Sasha and Array
[题目链接]:http://codeforces.com/contest/719/problem/E [题意] 给你一个数列,有两种操作1 l r x 给[l,r]区间上的数加上x, 2 l r 询问 ...
- 【Codeforces 1114B】Yet Another Array Partitioning Task
[链接] 我是链接,点我呀:) [题意] 让你把数组分成k个连续的部分 使得每个部分最大的m个数字的和最大 [题解] 把原数组降序排序 然后选取前m*k个数字打标记 然后对于原数组 一直贪心地取 直到 ...
- 【44.19%】【codeforces 727C】Guess the Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Codeforces 1042D】Petya and Array
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 把a[i]处理成前缀和 离散化. 枚举i从1..n假设a[i]是区间和的a[r] 显然我们需要找到a[r]-a[l]<t的l的个数 即a ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【36.86%】【codeforces 558B】Amr and The Large Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 797E】Array Queries
[题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问 ...
随机推荐
- 易企CMS仿站标签说明
头部标签: 每个页面都必须加的三大标签(将标签放入header.tpl里面,这样只需在每个模板中调用header.tpl即可): <title>{$seotitle}_{$sitename ...
- JAVA语言编程格式高级规范
作为一位开发人员,都要有严格的代码规范.为此我总结了一些代码规范案例. 目 录 1. 前言 2. 试用范围 3. JAVA命名规范-- 3.1 公共约定 3.2 Java文件.包 3.3 类.接口 ...
- python 上手
1.安装模块 cmd---“pip install [模块名]” 2.爬虫常用模块 requests beautifulsoup4 3.检查已安装的模块 cmd ---"pip list&q ...
- Window8.1下安装Matplotlib库
有两种方法: 直接选用一些预打包库软件,如WinPython, Python(x,y), Enthought Canopy, or Continuum Anaconda.这些软件中已包含有Matplo ...
- HTML5 video常用属性
一.视频video常用标签方法 <!-- controls 控制条,播放暂停等 controlslist 控制不允许全屏 不允许下载等 poster 封面 autoplay 自动播放 muted ...
- Java8新特性 Stream流式思想(二)
如何获取Stream流刚开始写博客,有一些不到位的地方,还请各位论坛大佬见谅,谢谢! package cn.com.zq.demo01.Stream.test01.Stream; import org ...
- linux系统下安装memcached
检查libevent 首先检查系统中是否安装了libevent rpm -qa|grep libevent 如果安装了则查看libevent的安装路径,后续安装时需要用到 rpm -ql libeve ...
- eas之执行sql的方式
客户端: 1. 有返回集合:查询 //查询出DB中所有该字段的值,与其进行比较,若有相同的则报错 String sql="select CFWuliaoCode fr ...
- C#第十四节课
函数的调用 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System ...
- tesuto-Mobius
求 \begin{equation*}\sum_{i=1}^n\sum_{j=1}^m[\gcd(i,j)=k]\end{equation*} 的值. 莫比乌斯反演吧. \begin{align*}& ...