首页 > 代码库 > 指针访问元素

指针访问元素

#include<iostream>#include<cmath>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<map>#include<cstdlib>#include<set>#include<ctime>#include<vector>#include<cstdio>#include<list>using namespace std;typedef long long ll;int INF=2147483647;int inf=-2147483648;#define read(x) scanf("%d",&x);#define fo(i,n) for(int i=1;i<=(n);i++)#define me(a) memset(a,0,sizeof(a));#define one(x) cout<<(x)<<endl;#define two(a,b) cout<<(a)<<" "<<(b)<<endl;int a[100005];int main(){    ios::sync_with_stdio(false);    int n;    cin>>n;    set<int>q;    for(int i=0;i<n;i++)    {        cin>>a[i];        q.insert(a[i]);    }    if(q.size()<=2)    {        one("YES");    }    else if(q.size()>3)    {        one("NO");    }    else    {        int a=*q.begin();        int b=*(++q.begin());        int c=*(++++q.begin());        if(c-b==b-a)        {            one("YES");        }        else        {            one("NO");        }    }    return 0;}

 

指针访问元素