hdu 4648

Magic Pen 6

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1361    Accepted Submission(s): 467


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 a 1,a 2,...a n (-100000000 <= a 1,a 2,...a n <= 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
大师对此题深感不屑,哎,弱菜表示,比赛当时脑残没做出来。看到大师淡定的写着多校6的逆天数学题,我等弱菜只有YM!
下面是代码:
 
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cstring>
#include<iostream>

using namespace std;

__int64 a[100000];
__int64 sum[1000000];
int n,m,ans;
bool flag;

int main(){
    while(scanf("%d%d",&n,&m)!=EOF){
       sum[0]=0;
       for(int i=1;i<=n;i++){
          scanf("%I64d",&a[i]);
          sum[i]=sum[i-1]+a[i]%m;//求出前n项和
       }
       ans=0,flag=true;
       for(int i=n;i>0&&flag;i--)
         for(int j=n;j>=i;j--){
               if((sum[j]-sum[j-i])%m==0){//找出中间最大的连续的可以整除m的,即为所求
                     ans=i;
                     flag=false;
                     break;
               }
       }
        cout<<ans<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值