Codeforces Round #616 (Div. 2)B. Array Sharpening

题目地址:https://codeforces.com/contest/1291/problem/B

题意:
	输入n,接着输入n个数字,这n个数字构成一个数组。
	你可以对数组中任意一个数字进行任意次数的-1操作。
	问:这个数组能不能变成一个锐化的数组。
数组锐化:三种形式
	1.递增:{01234}
	2.递减:{43210}
	3.只有一个坡度:{012343210}
解决方法:
	从头到尾遍历一遍,记录a[0] >= 0,a[1] >= 1......的数量,如果遇到a[i]<i,则退出并记录数量x;
	再从尾到头遍历一遍a[n - 1] >= 0, a[n - 2] >= 1....的数量,遇到>的话就退出并记录数量y;
	如果x+y>n则可以锐化,否则不可以。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#define ll long long
#define dd double
#define PI acos(-1.0)
#define f(i, x, y) for(ll i = x; i < y; i++)
using namespace std;
const ll MAXN = 2e5 + 5;

ll a[300005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll t; cin >> t;
	while (t--) {
		ll n; cin >> n;
		f(i, 0, n)cin >> a[i];
		ll x = 0;
		f(i, 0, n) {
			if (a[i] >= x) {
				x++;
			}
			else {
				break;
			}
		}
		ll y = 0;
		for (ll i = n - 1; i >= 0; i--) {
			if (a[i] >= y) {
				y++;
			}
			else {
				break;
			}
		}
		if (x + y > n) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值