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 ...
随机推荐
- 每日总结9.20-phoenix的连接
今天连了phoenix 出现了好多问题,欸 一点点解决,看那个电脑我头都要晕了,jar包和xml文件的问题,总之是解决了 怎么办,我还不会springboot,好多人都学了,我害怕.大家怎么都这么努力 ...
- MongoDB是一个NoSQL数据库,有着多种不同的命令和操作。以下是一些常见的MongoDB命令:
show dbs:列出所有数据库 use db_name:切换到指定的数据库 db.dropDatabase():删除当前数据库 db.createCollection("collectio ...
- 吉特日化MES-日化生产相关设备区分
在化妆品生产过程中约到各种各样的设备,对日化生产设备做一些简单的整理汇总,便于学习(其中设备根据其所在的产品以及领域会有一定的不同) 从产品的角度可以将产品划分为: (1) 乳化剂类产品 (2) 分类 ...
- 'parent.relativePath' of POM com.qbb:log_record_elegant:1.0-SNAPSHOT points at com.qbb:qiu_code instead of org.springframework.boot:spring-boot-starter-parent
完整的错误: 'parent.relativePath' of POM com.qbb:log_record_elegant:1.0-SNAPSHOT (F:\QbbCode\qiu_code\log ...
- 文档理解的新时代:LayOutLM模型的全方位解读
一.引言 在现代文档处理和信息提取领域,机器学习模型的作用日益凸显.特别是在自然语言处理(NLP)技术快速发展的背景下,如何让机器更加精准地理解和处理复杂文档成为了一个挑战.文档不仅包含文本信息,还包 ...
- 一款开源免费美观的WinForm UI控件库 - ReaLTaiizor
前言 今天推荐一款基于MIT license开源.免费.美观的.NET WinForm UI控件库:ReaLTaiizor. 什么是WinForm? WinForm是一个传统的桌面应用程序框架,它基于 ...
- The fourth day learning summary
一.for 循环循环就是重复做某件事,for循环是python提供第二种循环机制(第一种是while循环),理论上for循环能做的事情,while循环都可以做.目的:之所以要有for循环,是因为for ...
- 通过工厂函数封装返回app对象
main.py #主文件 import os from app import create_app # 通过环境变量设置项目运行时使用的配置文件,这里就手动设置以下了,一般部署的时候通过脚本等设置. ...
- MySQL 8.0.32 InnoDB ReplicaSet 配置和手动切换
1.环境准备 主库:192.168.137.4 mytest3 从库:192.168.137.5 mytest4 MySQL: 8.0.32 2.配置 ReplicaSet 实例 启动 mysql s ...
- python tkinter使用(五)
python tkinter使用(五) 本篇文章讲述tkinter 中treeview的使用 Treeview是一个多列列表框,可以显示层次数据. #!/usr/bin/python3 # -*- c ...