cf-div2-856c

题目链接:https://codeforces.com/contest/1816/problem/C

我是傻逼,否了自己的第一直觉。。。

思路:
构造方法:以最后一个值的数值x为基准,把所有的的数字(除第一个)调整为x
以n的奇偶性分为两种情况。
当n为奇数时:
yxy
当n为偶数时:
yx

代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
long long num[N];
void solve(){
    int n;
    cin>>n;
    for (int i=1;i<=n;i++) cin>>num[i];
    for (int i=n-1;i>1;i--){
        num[i-1] -= (num[i]-num[i+1]);
        num[i] -= (num[i]-num[i+1]);
    }
    if (n&1) cout<<"Yes\n";
    else{
        if (num[1]<=num[2]) cout<<"Yes\n";
        else cout<<"No\n";
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    T = 1;
    cin>>T;
    while(T--) solve();
    return 0;
}
posted @   安潇末痕  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示