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. C++名人的网站 转

    正如我们可以通过计算机历史上的重要人物了解计算机史的发展,C++相关人物的网站也可以使我们得到最有价值的参考与借鉴. 正如我们可以通过计算机历史上的重要人物了解计算机史的发展,C++相关人物的网站也可 ...

  2. ZOJ 3332 Strange Country II

    Strange Country II Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge You want to v ...

  3. 学习使用turtlebot2——turtlebot2上使用Hokuyo激光雷达(型号UST-10LX)

    目标     在turtlebot2上添加Hokuyo激光雷达传感器,使用激光雷达调用gmapping进行建图. 配置情况     电脑使用Ubuntu 14.04版本,ROS为 Indigo,激光雷 ...

  4. minikube操作命令

    1. 下载minikube   https://storage.googleapis.com/minikube/releases/v0.16.0/minikube-linux-amd64     ch ...

  5. delphi ----处理SQL server主键自增,并给定值

    获取一个表中最大的值. function GetNEWID(tablename: string): string; begin Result:=''; with DMW_Public.DQ_Pub d ...

  6. 找不到ifconfig命令

    对于新安装的系统,可能会缺少ifconfig命令,这是因为少安装了net-tools工具,所以只要安装上即可. yum install net-tools -y

  7. 我的Android进阶之旅------>解决Error: specified for property 'mergedManifest' does not exist.

    错误描述 刚运行从Github上面下载而来的代码时,爆了如下所示的bug,错误描述如下所示: Error:A problem was found with the configuration of t ...

  8. Linux(4)- centos7安装python3、Linux下安装、配置virtualenv、确保开发环境的一致性、虚拟环境之virtualenvwrapper、vim

    一.centos7安装python3 1.下载python3的源码包 下载地址:https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz cd ...

  9. python数据类型二(列表和元组)

    一.列表 1.1 列表的介绍 列表是python的基本数据类型之一,其他编程语言也有类似的数据类型,比如JS中的数组,java中的数组等等,它是以[]括起来,每个元素用逗号隔开,而且可以存放各种数据类 ...

  10. 系列文章(二):从WLAN的安全威胁,解析电信诈骗的技术症结——By Me

    导读:互联网的无线接入已经成为大趋势,其中无线局域网(又称为WLAN,Wireless Local AreaNetwork)以其使用方便.组网灵活.可扩展性好.成本低等优点,成为互联网特别是移动互联网 ...