题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776
题目让你求是否有区间的和是m的倍数。
预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续子列可以组成m的倍数。
1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm> 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <cstdio> 7 #include <vector> 8 #include <cmath> 9 #include <ctime> 10 #include <list> 11 #include <set> 12 #include <map> 13 using namespace std; 14 typedef long long LL; 15 typedef pair <int, int> P; 16 const int N = 1e5 + 5; 17 int a[N], cnt[N]; 18 19 int main() 20 { 21 int t, n, k; 22 scanf("%d", &t); 23 while(t--) { 24 scanf("%d %d", &n, &k); 25 memset(cnt, 0, sizeof(cnt)); 26 bool ok = false; 27 for(int i = 1 ; i <= n ; ++i) { 28 scanf("%d", a + i); 29 a[i] = (a[i] + a[i - 1]) % k; 30 cnt[a[i]]++; 31 if(cnt[a[i]] > 1 || !a[i]) 32 ok = true; 33 } 34 if(ok) 35 printf("YES "); 36 else 37 printf("NO "); 38 } 39 return 0; 40 }