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 ...
随机推荐
- OPC 协议数据采集
kepserver OPC Connectivity Suite 让系统和应用程序工程师能够从单一应用程序中管理他们的 OPC 数据访问 (DA) 和 OPC 统一架构 (UA) 服务器.通过减少 ...
- 【LOJ NOI Round#2 Day1 T1】单枪匹马(矩阵乘法)
题目传送门 操作二要求的东西是一个循环迭代的东西,手推相邻两项找下规律,发现相邻两项的分子分母间含有线性关系,考虑用矩阵乘法求解.对于 \([1,n]\)的询问,从后往前倒推, \(x_{n-1}=a ...
- 第二章 若依JFlow流程模型设计
若依-JFlow框架如何拉取.配置并运行请查看这篇文章:<第一章 若依-JFlow的配置与启动> 上一节我们讲解了如何拉取若依-JFlow框架代码并配置运行,这一部分我们就以公司员工请假的 ...
- 理解Mysql索引原理及特性
作为开发人员,碰到了执行时间较长的sql时,基本上大家都会说"加个索引吧".但是索引是什么东西,索引有哪些特性,下面和大家简单讨论一下. 1 索引如何工作,是如何加快查询速度 索引 ...
- Java并发(二十)----synchronized原理进阶
1.小故事 故事角色 老王 - JVM 小南 - 线程 小女 - 线程 房间 - 对象 房间门上 - 防盗锁 - Monitor-重量级锁 房间门上 - 小南书包 - 轻量级锁 房间门上 - 刻上小南 ...
- 在arm架构的银河麒麟系统部署Nginx
以下是在arm架构的银河麒麟系统上部署Nginx的详细步骤: 1. 创建文件夹 首先,在合适的位置创建必要的文件夹.在本例中,我们将创建/opt/nginx和/usr/src/nginx两个文件夹. ...
- ElasticSearch之cat templates API
命令样例如下: curl -X GET "https://localhost:9200/_cat/templates?v=true&pretty" --cacert $ES ...
- Python——第五章:模块(Module)、自定义模块、第3方开源模块、包(Package)
什么是模块(Module)? 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多代码按功能分组,分别放到不同的文件里,这 ...
- JavaFx 打包jar(六)
JavaFx 打包jar(六) JavaFX 从入门入门到入土系列 我们编写了不少javafx,那么如何打包成jar给用户呢?下面我给出比较全的打包方式. 打包jar 下面我给出比较全的打包方式. 1 ...
- Tailscale 基础教程:Headscale 的部署方法和使用教程
Tailscale 是一种基于 WireGuard 的虚拟组网工具,它在用户态实现了 WireGuard 协议,相比于内核态 WireGuard 性能会有所损失,但在功能和易用性上下了很大功夫: 开箱 ...