sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1126    Accepted Submission(s): 494

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.
 
Output
Output T lines, each line print a YES or NO.
 
Sample Input
2
3 3
1 2 3
5 7
6 6 6 6 6
 
Sample Output
YES
NO
 
Source

思路:当有两个前缀和相等,可以得到这段区间的和整除m;

   余m==0特判;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 0.00000000001
const int N=5e3+,M=1e6+,inf=1e9+,mod=;
int flag[N];
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
memset(flag,,sizeof(flag));
scanf("%d%d",&x,&z);
int ans=,sum=;
for(i=;i<x;i++)
{
scanf("%d",&y);
sum+=y;
sum%=z;
if(flag[sum])
ans=;
flag[sum]=;
}
if(ans||flag[])
printf("YES\n");
else
printf("NO\n");
}
return ;
}

hdu 5776 sum 前缀和的更多相关文章

  1. HDU 5776 sum (前缀和)

    题意:给定 n 个数,和 m,问你是不是存在连续的数和是m的倍数. 析:考虑前缀和,如果有两个前缀和取模m相等,那么就是相等的,一定要注意,如果取模为0,就是真的,不要忘记了,我当时就没记得.... ...

  2. HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题

    分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...

  3. HDU 5776 sum (模拟)

    sum 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5776 Description Given a sequence, you're asked ...

  4. HDU 5776 sum (思维题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...

  5. HDU 5776 sum(抽屉原理)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=5776 Problem Description Given a sequence, you're ask ...

  6. HDU 5776 sum

    猜了一下,发现对了.n>m是一定有解的.所以最多m*m暴力,一定能找到.而T较小,所以能过. #pragma comment(linker, "/STACK:1024000000,10 ...

  7. HDU 5776 sum( 鸽巢定理简单题 )

    链接:传送门 题意:给一个长为 n 的串,问是否有子串的和是 m 的倍数. 思路:典型鸽巢定理的应用,但是这里 n,m 的大小关系是不确定的,如果 n >= m 根据定理可以很简单的判定是一定有 ...

  8. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  9. HDU 5776

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 求是否有区间的和是m的倍数 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续子列可以组 ...

随机推荐

  1. SpringBoot专题2----springboot与schedule的激情相拥

    Schedule:计划,任务.就是我们常说的定时任务.这在我们做一些系统的时候,是经常需要用到的.比如:定时更新一些数据,定时更新索引,都需要这样的一个功能. 第一:创建一个名为springboot- ...

  2. idle命令行按ALT+P重复调出上个语句

    idle命令行按ALT+P重复调出上个语句

  3. python基础之类的封装

    从封装本身的意思去理解,封装就好像是拿来一个麻袋,把小猫,小狗,小王八,还有alex一起装进麻袋,然后把麻袋封上口子.但其实这种理解相当片面 一 封装什么 你钱包的有多少钱(数据的封装) 你的性取向( ...

  4. numpy.random.random & numpy.ndarray.astype & numpy.arange

    今天看到这样一句代码: xb = np.random.random((nb, d)).astype('float32') #创建一个二维随机数矩阵(nb行d列) xb[:, 0] += np.aran ...

  5. 对比MySQL,你究竟在什么时候更需要MongoDB(转)

    译文:对比MySQL,你究竟在什么时候更需要MongoDB 原文链接: When Should I Use MongoDB rather than MySQL (or other RDBMS): Th ...

  6. 0408-服务注册与发现-Eureka常用配置

    一.概述 参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_appendix ...

  7. Python集合方法整理(Day9)

    #作用:去重,关系运算, #定义: 知识点回顾 可变类型是不可hash类型 不可变类型是可hash类型 #定义集合: 集合:可以包含多个元素,用逗号分割, 集合的元素遵循三个原则: 1:每个元素必须是 ...

  8. day3-python的函数及参数

    函数式编程最重要的是增强代码的重用性和可读性 1 2 3 4 def 函数名(参数):     ...     函数体     ... 函数的定义主要有如下要点: def:表示函数的关键字 函数名:函 ...

  9. 微信小程序组件progress

    基础内容progress:官方文档 Demo Code: Page({ data:{ percent:0 }, onReady:function(){ this.percentAdd(); }, pe ...

  10. PAT 天梯赛 L1-002 【递归】

    题目链接 https://www.patest.cn/contests/gplt/L1-002 题意 给出一个数字 和一个字符 画出 可用数字下的最大沙漏,并且输出剩余没用掉的符号数 思路 可以先打一 ...