HDU 5776 sum
来源:互联网 发布:dct水印算法 matlab 编辑:程序博客网 时间:2024/06/05 02:02
Problem Description
Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO
Input
The first line of the input has an integer T (1≤T≤10 ), which represents the number of test cases.
For each test case, there are two lines:
1.The first line contains two positive integers n, m (1≤n≤100000 , 1≤m≤5000 ).
2.The second line contains n positive integers x (1≤x≤100 ) according to the sequence.
For each test case, there are two lines:
1.The first line contains two positive integers n, m (
2.The second line contains n positive integers x (
Output
Output T lines, each line print a YES or NO.
Sample Input
23 31 2 35 76 6 6 6 6
Sample Output
YESNO把前缀和对m取模,只要有相同的必然可以找到。#include<set>#include<map>#include<cmath>#include<stack>#include<queue>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define rep(i,j,k) for (int i = j; i <= k; i++)#define per(i,j,k) for (int i = j; i >= k; i--)using namespace std;typedef long long LL;const int low(int x) { return x&-x; }const double eps = 1e-8;const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e5 + 10;int T, n, m, x, y, s[N];void solve(){ rep(i, 0, m - 1) { if (s[i] > 1) { printf("YES\n"); return; } } printf("NO\n");}int main(){ scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); memset(s, y = 0, sizeof(s)); s[0] = 1; rep(i, 1, n) { scanf("%d", &x); s[(y += x) %= m]++; } solve(); } return 0;}
0 0
- HDU 5776 sum
- hdu 5776 sum
- HDU 5776 sum
- HDU-5776 Sum
- HDU 5776 sum
- HDU 5776 sum
- HDU 5776 sum
- BC85# HDU 5776 sum
- HDU 5776 sum
- Hdu 5776 sum
- HDU 5776 sum(数学)
- HDU 5776 (sum 前缀和)
- hdu 5776 sum 尺取法
- HDU 5776 sum(水~)
- hdu 5776 sum (抽屉原理)
- HDU - 5150 Sum Sum Sum
- hdu 5150 sum sum sum
- hdu 5150 Sum Sum Sum
- 学习写makefile
- 程序员喜欢的9款最佳的Linux文件比较工具
- NOJ 1031 建筑群最长坡值 简单dp
- POJ 1151
- Struts2中的constant配置详解
- HDU 5776 sum
- Java 设计模式之原型模式的详解(创建模式)
- LeetCode 347 Top K Frequent Elements
- ntlk入门函数解释(text相加, join, split, 数组坐标调用)
- JavaScript测试工具之Karma-Jasmine的安装和使用详解
- LeetCode 71 Simplify Path
- libusb-1.0.20移植到RT5350原厂SDK
- HDU 5777 domino
- Java Code Styles