time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You're given an array b of length n. Let's define another array a , also of length n, for which ai=2bi (1≤i≤n ).
Valerii says that every two non-intersecting subarrays of a have different sums of elements. You want to determine if he is wrong. More formally, you need to determine if there exist four integers l1,r1,l2,r2 that satisfy the following conditions:
- 1≤l1≤r1<l2≤r2≤n ;
- al1+al1+1+…+ar1−1+ar1=al2+al2+1+…+ar2−1+ar2
If such four integers exist, you will prove Valerii wrong. Do they exist?
An array c is a subarray of an array d if cc can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100 ). Description of the test cases follows.
The first line of every test case contains a single integer n (2≤n≤1000 ).
The second line of every test case contains n integers b1,b2,…,bn (0≤bi≤10^9 ).
Output
For every test case, if there exist two non-intersecting subarrays in a that have the same sum, output YES on a separate line. Otherwise, output NO on a separate line.
Also, note that each letter can be in any case.
Example
input
Copy
1. 2 2. 6 3. 4 3 0 1 2 0 4. 2 5. 2 5
output
Copy
1. YES 2. NO
Note
In the first case, a=[16,8,1,2,4,1] . Choosing l1=1 , r1=1 , l2=2 and r2=6 works because 16=(8+1+2+4+1) .
In the second case, you can verify that there is no way to select to such subarrays.
这道题 分两种情况:
- bi中有两个数一样
- bi中的数两两不同
首先对于第一种情况,不妨设 bj=bk,其中j<k ,则有解为
l1=r1=j,l2=r2=k
输出YES
对于第二种情况,显然此时在二进制下无论选择任何 bi进行和运算,都不会有进位,所以若要满足条件,必定存在 bx=by,与条件矛盾。此时应输出NONO
因此思路是:判断是否有重复元素。具体实现看代码。
#include <iostream> #include <algorithm> using namespace std; int a[20000]; int n,t; int main() { cin>>t; while(t--) { cin>>n; bool flag=0; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+1+n); for(int i=2;i<=n;i++) if(a[i]==a[i-1]) { flag=1; break; } if(!flag) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0; }