题意:给定 n 个数,和 m,问你是不是存在连续的数和是m的倍数。

析:考虑前缀和,如果有两个前缀和取模m相等,那么就是相等的,一定要注意,如果取模为0,就是真的,不要忘记了,我当时就没记得。。。。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int vis[maxn]; int main(){
// ios::sync_with_stdio(false);
int T, q; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
LL sum = 0;
memset(vis, 0, sizeof(vis));
bool ok = false;
vis[0] = 1;
for(int i = 0; i < n; ++i){
scanf("%d", &q);
sum += q;
if(vis[sum%m]) ok = true;
vis[sum%m] = 1;
}
printf("%s\n", ok ? "YES" : "NO");
}
return 0;
}

HDU 5776 sum (前缀和)的更多相关文章

  1. hdu 5776 sum 前缀和

    sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  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. mysql连接超时

    这几天在跟踪一个项目的时候,老是发现mysql连接报timeout的异常. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException ...

  2. iso中AutoLayout和Autoresizing Mask的区别

    •在iOS6之前,关于屏幕旋转的适配和iPhone,iPad屏幕的自动适配,基本都是由Autoresizing Mask来完成的.但是随着大家对iOS App的要求越来越高,以及今后可能出现的多种屏幕 ...

  3. &引用的问题

    C++中&可以代表引用也代表取地址符. 引用这一方面略微有点头大. 注意: 1)引用的函数可以作为左值 一个简单的作为左值的例子 #include <iostream> using ...

  4. *ecshop 模板中foreach用法详解

    1.foreach分以下几个参数 from, item, name, iteration, index 2.使用foreach循环      如果php要传递一个数组(如:$array)给ecshop ...

  5. 【英语】Bingo口语笔记(71) - shit系列

  6. windows xp 安装mysql5.6.17-ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password

    .zip解压后没有setup 没有my.ini 1.安装方法 bin目录下执行以下: E:\mysql-5.6.17-win32\bin>mysqld install MySQL --defau ...

  7. Bootstrap初级用户谈谈网页在手机上的显示效果优化

    本人之前已经使用Bootstrap有一段时间了,但是之前做出的网站都只是在电脑端使用,没有注意过手机端的显示效果.这两天自己使用Bootstrap做了一个简单的Web个人日志系统,想在手机端也使用,桌 ...

  8. [再寄小读者之数学篇](2014-11-19 $\sin x/x$ 在 $(0,\pi/2)$ 上递增)

    $$\bex \frac{\sin x}{x}\nearrow. \eex$$ Ref. [Proof Without Words: Monotonicity of $\sin x/x$ on $(0 ...

  9. YII 配置文件

    用YIIFramework的库开发 .... Yii::createWebApplication($config); //没有run Yii::import(class1,true),在将class1 ...

  10. 软件推荐列表(Recommand Software)

    1.Nutstore(https://jianguoyun.com/) Nutstore是一款云端同步软件.类似的有微软的OneDrive(旧名SkyDrive).Google Cloud Drive ...