Magic Pen 6
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.
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)
1 6
3 3
2 3 6
2 5
1 3
2
0
The magic pen can be used only once to scratch out consecutive students.
#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的更多相关文章
- HDU 4648 Magic Pen 6 (。。。。。。。。。。)
Magic Pen 6 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- hdu 4648 - Magic Pen 6(“水”题)
摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...
- HDU 4648 Magic Pen 6
题目链接 6Y什么水平.. #include <cstdio> #include <cstring> #include <string> #include < ...
- HDU 4648 Magic Pen 6 思路
官方题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...
- HDU-4648 Magic Pen 6 简单题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4648 求遍前缀和,然后扫描标记下就可以了... //STATUS:C++_AC_453MS_1792K ...
- 【 2013 Multi-University Training Contest 5 】
HDU 4647 Another Graph Game 如果没有边的作用,显然轮流拿当前的最大值即可. 加上边的作用,将边权平均分给两个点,如果一个人选走一条边的两个点,就获得了边的权值:如果分别被两 ...
- 《割绳子》《蜡笔物理学》《Contre Jour》《顽皮鳄鱼爱洗澡》等游戏用Box2D引擎实现物理部分的方法(转)
从最热门游戏排行榜和flash游戏网站上,你能看到什么?许多2D游戏都有非常出色的物理学和美术设计.现在我们要学习那些游戏使用了什么物理学以及如何用Box2D制作它们. 除了知道是“什么”,更重要的是 ...
- 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 ...
- [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 ...
随机推荐
- 2.9 while循环
while循环 <1>while循环的格式 while 条件: 条件满足时,做的事情1 条件满足时,做的事情2 条件满足时,做的事情3 ...(省略)... demo i = 0 whil ...
- 干货分享:让你分分钟学会 javascript 闭包(转)
闭包,是javascript中独有的一个概念,对于初学者来讲,闭包是一个特别抽象的概念,特别是ECMA规范给的定义,如果没有实战经验,你很难从定义去理解它.因此,本文不会对闭包的概念进行大篇幅描述,直 ...
- Win10上默认VS 2017以管理员身份运行
Win10上的UAC虽然是个好东西,但是对于使用开发工作的技术人员来说有时候也挺麻烦.这里有一个让VS2017无论如何都以管理员身份运行的方法. 1.进入VS2017的安装目录:..\Microsof ...
- Jedis
需要把jedis依赖的jar包添加到工程中 连接单机版 // 第一步:创建一个Jedis对象.需要指定服务端的ip及端口. Jedis jedis = new Jedis("192.168. ...
- JAVA 求数组中的最大值
package Code411;//求数组的最大值public class CodeArrayMax { public static void main(String[] args) { int ar ...
- linux 安装telnet命令及使用
一.CentOS下查看系统是否已安装telnetrpm -qa | grep telnettelnet-0.17-48.el6.x86_64telnet-server-0.17-48.el6.x86_ ...
- ajax与后台交互案例
BBS项目 //BBS项目,注册页面ajax请求 // 1.实现照片预览 $("#up_myhead").change(function () { // 获取input选择的文件 ...
- form组件
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['hobby'].choices ...
- Eigen::Matrix与array数据转换
1. 数组转化为Eigen::Matrix ]; cout << "colMajor matrix = \n" << Map<Matrix3i> ...
- Pyqt walk 在Windows查找文件
在任意目录下查找需要的文件如何操作呢? 其实很简单, WIN+E [桌面计算机]- 右上角“搜索 计算机” 这个就是Windows自带的文件搜索功能.自己做一个文件搜索的应该应该也挺好玩的. 知识要点 ...