Problem Description
In HIT, many people have a magic pen. Lilu0355 has a magic pen, darkgt has a magic pen, discover has a magic pen. Recently, Timer also got a magic pen from seniors.

At the end of this term, teacher gives Timer a job to deliver the list of N students who fail the course to dean's office. Most of these students are Timer's friends, and Timer doesn't want to see them fail the course. So, Timer decides to use his magic pen to scratch out consecutive names as much as possible. However, teacher has already calculated the sum of all students' scores module M. Then in order not to let the teacher find anything strange, Timer should keep the sum of the rest of students' scores module M the same.

Plans can never keep pace with changes, Timer is too busy to do this job. Therefore, he turns to you. He needs you to program to "save" these students as much as possible.

 
Input
There are multiple test cases.
The first line of each case contains two integer N and M, (0< N <= 100000, 0 < M < 10000),then followed by a line consists of N integers a1,a2,...an (-100000000 <= a1,a2,...an <= 100000000) denoting the score of each student.(Strange score? Yes, in great HIT, everything is possible)
 
Output
For each test case, output the largest number of students you can scratch out.
 
Sample Input
2 3
1 6
3 3
2 3 6
2 5
1 3
 
Sample Output
1
2
0

Hint

The magic pen can be used only once to scratch out consecutive students.

 
Source

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; const int N=1e5+; long long num[N],sum[N]; int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
sum[]=;
for(int i=;i<=n;i++){
scanf("%lld",&num[i]);
sum[i]=sum[i-]+num[i]%m;
}
int ans=,flag=;
for( int i=n; i>&&flag; i-- ){
for( int j=n; j>=i; j-- ){
if((sum[j]-sum[j-i])%m==){
ans=i;
flag=;
break;
}
}
}
cout<<ans<<endl;
}
return ;
}

Magic Pen 6的更多相关文章

  1. HDU 4648 Magic Pen 6 (。。。。。。。。。。)

    Magic Pen 6 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  2. hdu 4648 - Magic Pen 6(“水”题)

    摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...

  3. HDU 4648 Magic Pen 6

    题目链接 6Y什么水平.. #include <cstdio> #include <cstring> #include <string> #include < ...

  4. HDU 4648 Magic Pen 6 思路

    官方题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...

  5. HDU-4648 Magic Pen 6 简单题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4648 求遍前缀和,然后扫描标记下就可以了... //STATUS:C++_AC_453MS_1792K ...

  6. 【 2013 Multi-University Training Contest 5 】

    HDU 4647 Another Graph Game 如果没有边的作用,显然轮流拿当前的最大值即可. 加上边的作用,将边权平均分给两个点,如果一个人选走一条边的两个点,就获得了边的权值:如果分别被两 ...

  7. 《割绳子》《蜡笔物理学》《Contre Jour》《顽皮鳄鱼爱洗澡》等游戏用Box2D引擎实现物理部分的方法(转)

    从最热门游戏排行榜和flash游戏网站上,你能看到什么?许多2D游戏都有非常出色的物理学和美术设计.现在我们要学习那些游戏使用了什么物理学以及如何用Box2D制作它们. 除了知道是“什么”,更重要的是 ...

  8. Codeforces CF#628 Education 8 D. Magic Numbers

    D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. [8.3] Magic Index

    A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted ar ...

随机推荐

  1. Beamer 跳到另外一页

    \documentclass[english]{beamer}\usepackage{babel} \begin{document} \begin{frame}\frametitle{the refe ...

  2. 简单管理员权限与几个常用的PHP 常用函数,in_array(),explode(),implode(),join(),str_replace()

    先把今天要用的几个函数罗列出来: //explode()转换成数组,implode()转化成字符串 explode("分隔符",需要被分割的字符串或变量) $priv=" ...

  3. PHP微信公众号JSAPI网页支付(上)

    一.使用场景以及说明 使用场景:商户已有H5商城网站,用户通过消息或扫描二维码在微信内打开网页时,可以调用微信支付完成下单购买的流程. 说明:1.用户打开图文消息或者扫描二维码,在微信内置浏览器打开网 ...

  4. mybatis(入门级项目)

    框架的搭建:(两个java类,两个xml配置文件) 1.导入jar包,日志debug文件以及数据库的参数文件 2.建立持久化类(和数据库的列值相同的类) user类的一个扩展类: userQueryV ...

  5. tp5入门

    runtime目录里的文件是临时文件,可随时删除 在tp5里,命名空间对应了文件的所在目录,app命名空间通常代表了文件的起始目录为application,而think命名空间则代表了文件的起始目录为 ...

  6. selenium——find_element_by_xx 与 find_element(By.XX,'XXXX')

  7. Python--抽象类接口类

    一. 继承有两种用途: """ 一:继承基类的方法,并且做出自己的改变或者扩展(代码重用) 二:声明某个子类兼容于某基类,定义一个接口类Interface,接口类中定义了 ...

  8. 转载:.Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法

    .Net 程序集 签名工具sn.exe 密钥对SNK文件 最基本的用法 阐述签名工具这个概念之前,我先说说它不是什么: 1.它不是用于给程序集加密的工具,它与阻止Reflector或ILSpy对程序集 ...

  9. P4147 玉蟾宫--单调栈

    P4147 玉蟾宫 题目背景 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. 题目描述 这片土地被分成N*M个格子,每个格子 ...

  10. intellij idea创建maven项目

    1.安装好JDK,Tomcat,安装好maven: 2.配置maven全局变量:file->Other Settings ->Default Settings->Build,Exec ...