B. Valerii Against Everyone(思考)

https://codeforces.com/contest/1438/problem/B


アイデア:biの範囲は1e9であるため、最初にa []配列を計算するという観点から始めることは不可能です。

サンプルを見ると、2 ^ 4; 2 ^ 4 = 2 ^ 3 + 2 ^ 2 + 2 ^ 1 + 2 ^ 0 +1;があります。

1が実際には2 ^ 0であることがわかります。つまり、数値を他の数値で包括的に表すことができる場合は、少なくとも2つの0が必要です。2つの0がある場合、l1 = r1とl2 = r2はそれぞれです。それに等しい2つの数で十分です。直接満たされる他の2つの同じ番号があります。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
map<LL,LL>map1;
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n;cin>>n;
    map1.clear();
    for(LL i=1;i<=n;i++) {
        LL x;cin>>x;
        map1[x]++;
    }
    bool flag=1;
    for(auto i:map1){
        if(i.second>=2){
            flag=0;
            cout<<"YES"<<endl;
            break;
        }
    }
    if(flag==1){
        cout<<"NO"<<endl;
    }
  }
return 0;
}

 

おすすめ

転載: blog.csdn.net/zstuyyyyccccbbbb/article/details/112990823