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. [物理学与PDEs]第5章第3节 守恒定律, 应力张量

    5. 3 守恒定律, 应力张量 5. 3. 1 质量守恒定律 $$\bex \cfrac{\p \rho}{\p t}+\Div_y(\rho{\bf v})=0.  \eex$$ 5. 3. 2 应 ...

  2. H5取经之路——添加hover实现特定效果

    一.鼠标指上后显示二维码,效果图如下: 鼠标未指上时: 鼠标指上后: 代码如下: .div1 .li2 .code_wexin{ width: 0px; height: 0px; position: ...

  3. RT-SA-2019-003 Cisco RV320 Unauthenticated Configuration Export

    Advisory: Cisco RV320 Unauthenticated Configuration Export RedTeam Pentesting discovered that the co ...

  4. MySQL入门(参考官网)

    目录 一.登陆和退出 1. 远程主机 2. 登陆本机 3. 退出mysql 二.输入查询 三.创建和使用数据库 3.1 创建和选择数据库 3.2 创建表 3.3 将数据加载到表中 3.4 操作表格 3 ...

  5. 一些Js操作

    一.after()和before()方法的区别 after()——其方法是将方法里面的参数添加到jquery对象后面去:    如:A.after(B)的意思是将B放到A后面去:    before( ...

  6. 浅谈axios

    在我们的项目中有用到: fetch有直接用的,也有自己封装之后用的; vue-resource在vue1的时候使用,把方法抽象出来后,总需要往方法里传 this.$http ,感觉是个超级不爽的设计, ...

  7. 在window系统上安装redis服务-Invalid argument during startup: Failed to open the .conf

    当前redis版本: redis-cli -v redis-cli 3.0.503 网上给的命令(在redis所在文件夹下执行): redis-server –service-install redi ...

  8. 记事本:CSS

    css更多的是一种用来修饰HTML的语言 CSS的三种引入方式 1.行内样式:一般不会这样写,如果想选择某一个,可以用之后内部样式中更加详细的选中方式 行内的优先级最高 <p style=&qu ...

  9. day14 带参装饰器、迭代器、生成器

    """ 今日内容: 1.带参装饰器及warps 2.迭代器 3.生成器 """ """ # 一.带参装饰器及w ...

  10. 关于含RecyclerView的fragment来回切换时页面自动滑动到底部的解决方法

    原因: 在fragment中来回切换时RecyclerView获得了焦点,而RecyclerView的 focusableOnTouchMode属性默认是true,所以在切换时RecyclerView ...