TOJ 1721 Partial Sums
Description
Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined as the sum of ai, ai+1, ..., aj.
You are supposed to calculate how many partial sums of a given series of numbers could be divided evenly by a given number m.
Input
There are multiple test, each contains 2 lines.
The first line is 2 positive integers n (n <= 10000 ) and m (m <= 5000).
The second line contains n non-negative integers a1, a2, ..., an. Numbers are separated by one or several spaces.
The input is ended by EOF.
Output
One test each line - the number of partial sums which could be divided by m.
Sample Input
5 4
1 2 3 4 5
6 7
9 8 7 6 5 4
Sample Output
2
3
Source
#include <stdio.h>
int main(int argc, char *argv[])
{
int n,m;
int a[];
int sum[];
while( scanf("%d %d" ,&n ,&m)!=EOF ){
int ans=;
int ca[]={};
for(int i=; i<n; i++){
scanf("%d",&a[i]);
if(i==){
sum[i]=a[i]%m;
}else{
sum[i]=(sum[i-]+a[i])%m;
}
if(sum[i]%m==)
ans++;
ca[sum[i]]++;
}
for(int i=; i<m; i++)
ans+=ca[i]*(ca[i]-)/;
printf("%d\n",ans);
}
return ;
}
TOJ 1721 Partial Sums的更多相关文章
- 51nod1161 Partial Sums
开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...
- Non-negative Partial Sums(单调队列)
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu 4193 Non-negative Partial Sums 单调队列。
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- 【计数】cf223C. Partial Sums
考试时候遇到这种题只会找规律 You've got an array a, consisting of n integers. The array elements are indexed from ...
- CodeForces 223C Partial Sums 多次前缀和
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)
ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...
- hdu 4193 - Non-negative Partial Sums(滚动数列)
题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...
- hdu 4193 Non-negative Partial Sums
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4193 题意:给出一个n数列,要求把前i(1<=i<=n)个数移到剩余数列的后面形成新的数列 ...
随机推荐
- perationalError: (2003, "Can't connect to MySQL server on u'192.168.1.6' (timed out)")
在Ubuntu(192.168.1.20)中部署项目后,mysql还在另外一台windows(192.168.1.6)机子上,ping windows时可以ping通,但是访问项目提示: perati ...
- 余额宝 vs. P2P网贷,谁更有生命力?
余额宝跟P2P网贷作为一个理财方式,要说谁更有生命力,那就必须从以下几个方面说起,一是收益性,二是风险性,三是流动性,下面从这几个方面来对比一下余额宝跟P2P网贷. 首先是收益性,作为投资理财者,第一 ...
- DOM--sql server
public List<LianHeData> select(int ID) { List<LianHeData> list = new List<LianHeData& ...
- 201621123012 《java程序设计》第2周学习总结
1. 本章学习总结 1.学习了java许多了基本语法,string函数,arraylist函数的各种功能方法和调用. 2.了解了除for循环之外的foreach循环 3.学习了各种数值类的包装 4.熟 ...
- Delphi XE8中Android开发有用的资源!
一,FireMonkey Component Library在XE8帮助(topics.chm)中的位置:FireMonkey Component Library,展示了FireMonkey控件在VC ...
- 强制json格式
- ExtJS 4.2.1学习笔记(一)——MVC架构与布局
1 ExtJS入门 1.1 支持所有主流浏览器 调试推荐:chrome.Safari.Firefox 1.2 推荐目录结构 - appname (包含所有程序代码,是根目录 ...
- \\.\Global\vmx86: 系统找不到指定的文件
使用vmware虚拟机时出现如下的错误: vmware安装无法打开内核设备 \\.\Global\vmx86: 系统找不到指定的文件 解决办法: 新建文件,将下面的代码拷贝进去: @Echo Off ...
- 关于zabbix _get返回Could not attach to pid的问题
分析:这是因为由于zabbix客户端没有权限,导致zabbix_server端无法获取到键值数据!! 解决:在客户端上添加用户sudo的权限就可以解决了. 验证:是脚本的话还要在脚本里加上sudo的命 ...
- ggplot你不知道的细节
例一 Michaelis-Menten动力学方程 这个例子中采用出自文献中的一组有关于浮萍氮摄取的数据,共2两个变量8个观测值,其中底物浓度与浮萍的氮取速率之间可以通过M-M动力学方程来进行描述.在这 ...