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

A. Shifting Stacks

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

然后上我第一遍的代码

#include 
#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 
#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的人傻了的图
Codeforces Round #703 (Div. 2) (自闭场)_第1张图片
剩下的题补完再更新

你可能感兴趣的:(Codeforces比赛记录,c++,算法)