hdu 4648
来源:互联网 发布:类似92game源码的平台 编辑:程序博客网 时间:2024/06/16 16:20
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4648
Magic Pen 6
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1857 Accepted Submission(s): 637
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.
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)
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 31 63 32 3 62 51 3
Sample Output
120HintThe magic pen can be used only once to scratch out consecutive students.
Source
2013 Multi-University Training Contest 5
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you: 4822 4821 4820 4819 4818
简单题,len从大到小,(sum[j+len]-sum[j])%M==0 len即为所求。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int MAX=100010;int sum[MAX];int main(){ int N,M; while(cin>>N>>M) { memset(sum,0,sizeof(sum)); for(int i=1;i<=N;i++) { int x; scanf("%d",&x); sum[i]=sum[i-1]+x; } bool flag=true; for(int i=N;i>=0&&flag;i--) { for(int j=0;j+i<=N;j++) { if((sum[j+i]-sum[j])%M==0) { cout<<i<<endl; flag=false; break; } } } } return 0;}
0 0
- hdu 4648
- hdu 4648
- hdu 4648
- HDU 4648
- hdu 4648 Magic Pen
- hdu 4648(dp)
- HDU 4648 magic pen
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- 怎么在eclipse的配置文件里指定jdk路径
- LeetCode: Reverse Nodes in k-Group [024]
- JavaWeb入门结束
- DBUtils使用详解【介绍的很详细】
- 整数分解成连续自然数之和问题(《编程之美》2.21节)研究
- hdu 4648
- Console类——方便向控制台读取与写入内容
- 如何batch跑matlab程序
- leetcode学习笔记:Trapping Rain Water
- java算法之下压栈来动态调整数组大小
- 第三十三题 输出容器中3个不同的数
- uva 11375 - Matches(递推)
- 黑马程序员——银行业务调度系统
- Struts2框架(一)