【T1T2】hrz的序列

6 篇文章 0 订阅

在这里插入图片描述

题解

首先求出有多少不同的元素(tt),若tt>3显然是不可能通过加上或减去一个数使得所有数相等;若tt<3,则可以通过让较小的数加上差值就可以平衡;对于tt=3的情况,按照从小到大是顺序排序,若是等差数列,则可以达到平衡。
注意数据范围: 1 0 15 10^{15} 1015,一共16位,用 l o n g   l o n g long\ long long long

代码

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<set>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define mem(a,s) memset(a,s,sizeof(a))
typedef long long ll;
const int N = 10000 + 10;
int n;
set<ll> s;
int main(){
 //   freopen("in.txt","r",stdin);
    int TT;
    cin>>TT;
    while(TT--){
        cin>>n;
        int tt = 0;
        if(s.size())
            s.clear();
        rep(i,1,n){
            ll x;
            cin >> x;
            if(tt<3&&s.find(x)==s.end()){s.insert(x);tt++;}
        }
        if(tt>3)
            cout << "NO\n";
        if(tt<3)cout<<"YES\n";
        if(tt==3){
            ll a[3];
            int tot = 0;
            for(auto x:s)
                {a[tot++] = x;}
            if ((a[2] - a[1]) != (a[1] - a[0]))
                cout << "NO\n";
            else
                cout << "YES\n";
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值