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. java导出简单写法

    List<SaleOrderExportDTO> list = TransferUtil.transferList(queryList, SaleOrderExportDTO.class) ...

  2. JavaWeb项目中文乱码问题

    1.从浏览器读数据乱码(post 请求方式) 前提是前端页面是UTF-8编码,因为服务器端默认采用ISO解码,所以乱码,在读取前加上: request.setCharacterEncoding(&qu ...

  3. 导出Excel功能的3种实现

    项目中总会用到Excel的导出功能,接触过好几个项目,发现有个项目的导出实现特别值得学习.这里学习顺带总结一下. 一.三种方法 我遇到的导出目前有3种处理: 每个功能一个导出方法: 写一个通用的Exp ...

  4. PAT 甲级 1003Emergency(Dijkstra最短路)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  5. ubuntu 使用串口picocom

    连上USB转串口 查看是否识别串口     dmesg | grep ttyUSB0 安装(mint / ubuntu): $ sudo apt-get install picocom 使用: 先赋予 ...

  6. Javascript调用WinForm方法

    window.external.MyMessageBox('javascript访问C#代码')

  7. Spring 的IOC容器之注解的方式

    1. 环境搭建 1.1 导入所需 jar 包 引入 IOC 容器必须的6个jar包; spring-aop-4.3.10.RELEASE.jar, Spring 框架的AOP的jar包; 1.2 创建 ...

  8. Java 之 GUI 编程

    GUI (Graphical User Interface, 图形用户接口) CLI (Command line User Interface, 命令行用户接口) Java 为 GUI 提供的对象都存 ...

  9. Pandas 如何去除、取消已经设置好的索引

    Outline 今天处理数据时遇到一个问题: 因为业务需要,我对 df 进行了建立索引. 具体如下: 下面走的是默认索引 给其设置索引: 取消索引 业务需求,我要取消掉上面设置的索引: So,之前设置 ...

  10. LAMP兄弟连 视频教程集

    电驴的资源:http://www.verycd.com/topics/2843130/?ref=msg