补写:Best Coder #85 1001 Sum(前缀和)
sum
Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO
The first line of the input has an integer T (1≤T≤101 \leq T \leq 101≤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≤1000001 \leq n \leq 1000001≤n≤100000, 1≤m≤50001 \leq m \leq 50001≤m≤5000). 2.The second line contains n positive integers x (1≤x≤1001 \leq x \leq 1001≤x≤100) according to the sequence.
Output T lines, each line print a YES or NO.
2
3 3
1 2 3
5 7
6 6 6 6 6
YES
NO
/*第一次来打BC,作为大一的大水B,水出一道,已经很高兴了*/
/*用前缀和来遍历每一个连续数列的和*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 100010
using namespace std;
long long a[N],sum[N];
int main()
{
//freopen("in.txt", "r", stdin);
int t;
int n,m;
scanf("%d",&t);
while(t--)
{
memset(sum,,sizeof sum);
memset(a,,sizeof a);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
}
int flag=;
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
if((sum[j]-sum[i-])%m==)
{
puts("YES");
flag=;
break;
}
}
if(!flag)
break;
}
if(flag)
printf("NO\n");
}
return ;
} Close BestCoder Contest System 2.0 Copyright © - HDU ACM
补写:Best Coder #85 1001 Sum(前缀和)的更多相关文章
- Hash课堂测试补写
Hash课堂测试补写 测试要求: 利用除留余数法为下列关键字集合的存储设计hash函数,并画出分别用开放寻址法和拉链法解决冲突得到的空间存储状态(散列因子取0.75) 关键字集合:85,75,57,6 ...
- 用Emmet写CSS3属性会自动添加前缀
CSS3的很多属性都包含浏览器厂商前缀,用Emmet写CSS3属性会自动添加前缀,比如输入trs 会展开为: -webkit-transition: prop time; -moz-transitio ...
- 前端框架Bootstrap(10.7国庆补写)
框架的官网地址:https://v3.bootcss.com/ 主要学习Bootstrap框架提供的样式.组件.插件的使用. 首先下载到本地,在项目中导入使用: 下载的文件中包含:min.css的是压 ...
- HDU 5776 sum (BestCoder Round #85 A) 简单前缀判断+水题
分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #includ ...
- BestCoder Round #85 hdu5776 sum
sum 题意: 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出NO 输入描述 输入文件的第一行有一个正整数T,表示数据组数. 接下去有T组数据,每组数据的第一行有两个 ...
- hdu 5776 sum 前缀和
sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submi ...
- Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和
B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...
- HDOJ(1001) Sum Problem
这一套题做错了几次,按理说直接用等差数列求和公式就行了,主要是要考虑一些运算符的结核性问题: 四则运算符(+.-.*./)和求余运算符(%)结合性都是从左到右. 于是,我自己写了一个版本,主要是考虑( ...
- Codeforces 85 D. Sum of Medians
题目链接:http://codeforces.com/contest/85/problem/D 做法果然男默女泪啊..... 大概就是直接开了一个$vector$每次插入删除都用自带的$insert$ ...
随机推荐
- pycharm 2017新建文件添加编码方式等
file->setting->Editor->File and Code Templates->Python Script 添加 #!/usr/bin/python3# -*- ...
- java基础解析系列(七)---ThreadLocal原理分析
java基础解析系列(七)---ThreadLocal原理分析 目录 java基础解析系列(一)---String.StringBuffer.StringBuilder java基础解析系列(二)-- ...
- shell查找指定时间段内的文件
#!/bin/bash#20170905 输入参数格式echo "显示"$1"的备份文件"date_0=$1date_1=`expr $date_0 + 1`d ...
- JSP入门 Listener
实现HttpSessionListener 编写一个OnlineUserListener类 package anni; import java.util.List; import javax.serv ...
- Java数据结构和算法总结-数组、二分查找
前言:在平时开发中数组几乎是最基本也是最常用的数据类型,相比链表.二叉树等又简单很多,所以在学习数据和算法时用数组来作为一个起点再合适不过了.本篇博文的所有代码已上传 github ,对应工程的 ar ...
- Power Strings poj2406(神代码)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 29402 Accepted: 12296 D ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- ubuntu中运行python脚本
1. 运行方式一 新建test.py文件: touch test.py 然后vim test.py打开并编辑: print 'Hello World' 打开终端,输入命令: python test.p ...
- Python 开发之路
强烈推荐地表最强博客:http://www.cnblogs.com/wupeiqi Python开发[第一篇]:目录 Python开发[第二篇]:初识Python Python开发[第三篇]:Pyth ...
- WPF---Effect效果
在 WPF 中,可以使用 BitmapEffect 对象为每一个 Visual 对象生成各种各样的效果,一个 Visual 对象可以设置一种或多种 BitmapEffect 效果,WPF 内置了几种效 ...