-
题意:给你一组数\(b\),对于每个\(b_i\),相对应的\(a_i=2^{b_i}\),问你是否能找出两个不相交的区间,使得两个区间的\(a_i\)的元素和相等.
-
题解:对于任意一个\(2^k\),如果它只能由\(2^k\)相加得到的话,那么只能是他自己本身,或者这些\(2^k\)中含有相同元素,我们可以推一下,\(1,2,4,8,16,32,64\),\(8\)只能由自己或者\(4*2\),\(2*4\)得来,所以某个\(2^k\)必须出现多次,所以只要判断是否有相同元素即可.
-
代码:
int t; int n; int a[N]; map<int,int> mp; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>t; while(t--){ cin>>n; rep(i,1,n) cin>>a[i]; mp.clear(); bool flag=false; rep(i,1,n){ if(mp[a[i]]) {flag=true;break;} mp[a[i]]++; } if(flag) cout<<"YES\n"; else cout<<"NO\n"; } return 0; }
相关文章
- 11-30Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) B. Journey Planning(思维)
- 11-30Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维
- 11-30B. Double Matrix--- 思维题--Codeforces Round #557 (Div. 2)
- 11-30B. Draw!--简单思维题--Codeforces Round #541 (Div. 2)
- 11-30Codeforces Round #732 (Div. 2) B. AquaMoon and Stolen String(思维/字符串)
- 11-30Codeforces Round #652 (Div. 2)-B. AccurateLee(字符串,思维)
- 11-30Codeforces Round #682 (Div. 2) B. Valerii Against Everyone (思维)
- 11-30Codeforces Round #708 (Div. 2) B. M-arrays 思维+哈希表
- 11-30Codeforces Round #701 (Div. 2) B. Replace and Keep Sorted 思维
- 11-30Codeforces Round #721 (Div. 2) B. Palindrome Game (easy and hard version) (思维 + 简单博弈)