Codeforces Round #703 (Div. 2) (自闭场)

A. Shifting Stacks

这题我能记很久,直接给我打自闭了,从开赛一直到了最后,我就一个菜鸡
题意非常简单,给你n个数,让你把他们构造成递增的,然后只能从后往前,你直接想就行了,直接构造0 1 2 3 4 5 6 7 8 9…n如果可以的话,就是yes,不可以的话就是no

然后上我第一遍的代码

#include <bits/stdc++.h>
#define int long long
#define BUFF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int a[N];
signed main()
{
    /*  
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
*/
    int T;
    T = read();
    while (T--)
    {
        int n;
        n = read();
        bool flag = true;
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            a[i] = read();
        }
        for (int i = 1; i < n; i++)
        {
            int ans = a[i] - cnt;
            a[i] = cnt;
            cnt++;
            if (ans < 0)
            {
                flag = false;
                break;
            }
            a[i + 1] += ans;
            if (a[i] >= a[i + 1])
            {
                flag = false;
                break;
            }
        }
        if (a[n] <= a[n - 1])
        {
            flag = false;
        }
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

这个让人直接wa掉,因为我少了一个特判,如果n==1的时候,我要直接yes,而不是判断a[1]和a[0]的关系

然后下面是ac的代码

#include <bits/stdc++.h>
#define int long long
#define BUFF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
int a[N];
signed main()
{
    /*  
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
*/
    int T;
    T = read();
    while (T--)
    {
        int n;
        n = read();

        bool flag = true;
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            a[i] = read();
        }
        if (n == 1)
        {
            cout << "YES" << endl;
            continue;
        }
        for (int i = 1; i < n; i++)
        {
            int ans = a[i] - cnt;
            a[i] = cnt;
            cnt++;
            if (ans < 0)
            {
                flag = false;
                break;
            }
            a[i + 1] += ans;
            if (a[i] >= a[i + 1])
            {
                flag = false;
                break;
            }
        }
        if (a[n] <= a[n - 1])
        {
            flag = false;
        }
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

就加了一个特判就好了,我直接上图,我wa的人傻了的图
在这里插入图片描述
剩下的题补完再更新

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值