Codeforces 451B Sort the Array(水题)
题目连接:Codeforces 451B Sort the Array
题目大意:给出一个长度为n的序列,可以有一次机会旋转a[l]到a[r]之间的数,问说可否形成一个递增序列。
解题思路:将数组排下序,然后从前向后,从后向前寻找不同到位置,这段l~r是一定要旋转的,然后判断旋转后的符不符合递增。注意l>r的情况。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
ll a[N], b[N];
bool judge(int l, int r) {
for (int i = 0; i + l < r; ++i)
if (a[l + i] != b[r - i])
return false;
return true;
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n; cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i], b[i] = a[i];
sort(b, b + n);
int l = 0, r = n - 1;
while (l < n && b[l] == a[l])l++;
while (r >= 0 && b[r] == a[r])--r;
if (judge(l, r)) {
if (r < l)
l = r = 0;
cout << "yes" << endl << l + 1<< " " << r + 1 << endl;
}
else
cout << "no" << endl;
}
Codeforces 451B 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 660A A. Co-prime Array(水题)
题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input stand ...
- hdu 5532 Almost Sorted Array (水题)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
随机推荐
- 总结(3)--- 知识总结(内存管理、线程阻塞、GIL锁)
一.Python中是如何进行内存管理的? 垃圾回收:Python不像C++,Java等语言一样,他们可以不用事先声明变量类型而直接对变量进行赋值.对Python而言,对象的类型和内存都是在运行时确定的 ...
- Python 之 Numpy 框架入门
NumPy 目录 NumPy 基础使用 基本数据类型 创建基本数组 数组属性 数组生成 zeros.ones.empty 数组生成 numpy.zeros numpy.ones numpy.empty ...
- 你知道Spring中BeanFactoryPostProcessors是如何执行的吗?
Spring中的BeanFactoryPostProcessor是在Spring容器实例化Bean之后,初始化之前执行的一个扩展机制.它允许开发者在Bean的实例化和初始化之前对BeanDefinit ...
- Tainted canvases may not be exported,视频帧截图跨域
做原生相机拍照的时候遇见的有趣问题,视频流是上传到云服务器的在线链接,赋值到video的src上,然后使用canvas的drawImg方法去截取视频帧做照片,结果canvas报错视频跨域. 解决方案: ...
- 数字孪生结合GIS能给物流行业带来怎样的改变
随着科技的不断发展和创新,数字孪生技术和地理信息系统(GIS)正日益在各个行业中发挥重要作用.其中,物流行业作为一个复杂而庞大的系统,也能从数字孪生和GIS的结合中获得许多益处和改变. 数字孪生是指通 ...
- ElasticSearch之健康状态
参考Cluster health API. 命令样例,如下: curl -X GET "https://localhost:9200/_cluster/health?wait_for_sta ...
- ElasticSearch之cat repositories API
命令样例如下: curl -X GET "https://localhost:9200/_cat/repositories?v=true&pretty" --cacert ...
- Rust实现线段树和懒标记
参考各家代码,用Rust实现了线段树和懒标记. 由于使用了泛型,很多操作都要用闭包自定义实现. 看代码. // 线段树定义 pub struct SegmentTree<T: Clone> ...
- electron入门之配置镜像加速(四)
electron入门到入土,配置阿里镜像加速.为了防止后面我们打包龟速,需要给electron配置阿里镜像加速 在下面的文件内添加阿里镜像加速,你的文件位置不一定是这个 C:\Program File ...
- Java 在Excel中添加筛选器并执行筛选
以下内容介绍通过Java程序在Excel添加筛选器并执行筛选.程序需要使用Excel工具类库Free Spire.XLS for Java,本文中使用的是免费版,可在官网下载jar包,解压导入jar文 ...