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)个数移到剩余数列的后面形成新的数列 ...
随机推荐
- Window 7 Professional 多语言设置
1. 正常情况下,WINDOW系统只提供企业和旗舰版的语言切换的界面设置,其他版本没有. 2. 首先下载语言包,然后解压待用. 3. 以管理员身份运行命令窗口,如下输入: 4. 上面完成后,下载 ht ...
- 汇编Shellcode的技巧
汇编Shellcode的技巧 来源 https://www.4hou.com/technology/3893.html 本文参考来源于pentest 我们在上一篇提到要要自定义shellcode,不 ...
- bzoj1565【NOI2009】植物大战僵尸(最小割)
题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏.Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻.该款游戏包含多 ...
- django自定义rbac权限组件(二级菜单)
一.目录结构 二.表结构设计 model.py from django.db import models # Create your models here. class Menu(models.Mo ...
- 老男孩Day15作业:商城列表页面(静态)
一. 一.作业需求: 1.完成商城列表静态页面的抒写 二.博客地址:https://www.cnblogs.com/catepython/p/9205636.html 三.运行环境 操作系统:Win1 ...
- php 大文件读取
当你需要处理一个5G的文件里面的数据时,你会怎么做,将文件里面的内容全部读取到一个数组里面去? 显然这种做法对小文件是没有问题的,但是对于大文件还是不行的 这时就需要用到 yield 了 ,注意这是 ...
- CBoard 看板参数管理
看板设计采用简单Row+Column布局模式,每行总长度为12,每列对应一个图表,行高度可以调节,列高度集成行高 左边栏看板分类中,我的看板为当前用户创建的看板,普通看板分类通过分类管理维护,保存看板 ...
- ThinkPHP5.0中Request请求对象的使用和常用的操作
request的使用 第一种方法 在控制器头部添加request引用 然后在方法里调用 ‘instance’类 然后在调用方法: public function index($name='name') ...
- Optimizing and caching browser bundles...
扎心了,老铁!!! 他妈的,弄了几天都是卡在这里!!上网查了一下.说是我的内存不够,好吧.我慢慢等,然而让我等了好几天都没什么反应..两天了,一直卡在这里.今天在虚拟机也是发狠了. 我直接把虚拟机的内 ...
- java线程面试
1) 什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成 ...