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 ...
随机推荐
- 小白必知:AIGC 和 ChatGPT 的区别
原文 : https://openaigptguide.com/chatgpt-aigc-difference/ AIGC 和 ChatGPT 都是人工智能技术,但它们的功能和应用场景不同. AIGC ...
- PageHelper插件注意事项
PageHelper插件注意事项 使用PageHelper.startPage后要紧跟查询语句 下面的代码就有可能出问题: PageHelper.startPage(10, 10); if(param ...
- JavaWeb开发-CSS基础
2.CSS层叠样式表基本语法 层叠样式表,用来控制页面的样式 (1)CSS的三种引入方式 内部样式表:适合学习使用,将CSS代码写在style标签里面,style标签嵌套在title里 外部样式表:开 ...
- git 同时推送多个远程仓库
今天遇到个git的问题:需要同时提交到两个远程仓库 解决方法: git add . git commit -m '提交信息' git remote -v git remote add old_orig ...
- Chrome扩展的核心:manifest 文件(上)
大家好,我是dom哥.我正在写关于 Chrome 扩展开发的系列文章,感兴趣的可以点个小星星. Chrome 在全球浏览器市场份额独占 6 成,无论是对普通用户还是开发者,都是电脑里的必备利器.Chr ...
- NLP项目实战01--之电影评论分类
介绍: 欢迎来到本篇文章!在这里,我们将探讨一个常见而重要的自然语言处理任务--文本分类.具体而言,我们将关注情感分析任务,即通过分析电影评论的情感来判断评论是正面的.负面的. 展示: 训练展示如下: ...
- 18、defer
1.defer是什么? 字面意思来看,defer是延迟,推迟的意思 在go语言中,使用defer关键字来延迟一个函数或者方法的执行 2.defer能干嘛? 对象.close(),临时文件的删除 文件. ...
- Mongo 数据库备份和恢复命令
转载请注明出处: 在MongoDB中,使用mongodump和mongorestore命令来备份和恢复数据库 mongodump 1.使用方法: 使用 mongodump 命令可以备份MongoDB数 ...
- 数字孪生结合GIS能给物流行业带来怎样的改变
随着科技的不断发展和创新,数字孪生技术和地理信息系统(GIS)正日益在各个行业中发挥重要作用.其中,物流行业作为一个复杂而庞大的系统,也能从数字孪生和GIS的结合中获得许多益处和改变. 数字孪生是指通 ...
- java之switch用法
多条件判断,判断条件是等值判断时,可以用switch 比如: 变量level=0时,输出"非会员" 变量level=1时,输出"打9折" 变量level=2时, ...