设为首页 加入收藏

TOP

HDU 4648 Magic Pen 6
2014-11-23 20:16:33 来源: 作者: 【 】 浏览:9
Tags:HDU 4648 Magic Pen

Magic Pen 6
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 797 Accepted Submission(s): 282


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
2013 Multi-University Training Contest 5


Recommend
zhuyuanchen520
我对这题直接无语了,不应该啊,按理说他的余数应该要考虑正负啊,怎么题目的数据没有考虑呢,从题目的数据来看出现了负的余数,就把他化成正的,进行统一。这万一原来的余数是正的,你去掉后余数变成负的显然不满足啊。

#include    
#include    
#include    
#include    
#include    
#define N 110000   
using namespace std;  
int a[N];  
int main()  
{  
    //freopen("data.in","r",stdin);   
    int n,m;  
    while(scanf("%d %d",&n,&m)!=EOF)  
    {  
        for(int i=1;i<=n;i++)  
        {  
            scanf("%d",&a[i]);  
        }  
        mapp;  
        p.clear();  
        int s = 0;  
        int Max = 0;  
        for(int i=1;i<=n;i++)  
        {  
            s +=a[i];  
            s = (s%m+m)%m;  
            if(s==0)  
            {  
                Max = max(Max,i);  
            }  
            if(p[s]==0)  
            {  
                p[s] = i;  
            }else  
            {  
                Max = max(i-p[s],Max);  
            }  
        }  
        printf("%d\n",Max);  
    }  
    return 0;  
}  

#include 
#include 
#include 
#include 
#include 
#define N 110000
using namespace std;
int a[N];
int main()
{
    //freopen("data.in","r",stdin);
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        mapp;
        p.clear();
        int s = 0;
        int Max = 0;
        for(int i=1;i<=n;i++)
        {
            s +=a[i];
            s = (s%m+m)%m;
            if(s==0)
            {
                Max = max(Max,i);
            }
            if(p[s]==0)
            {
                p[s] = i;
            }else
            {
                Max = max(i-p[s],Max);
            }
        }
        printf("%d\n",Max);
    }
    return 0;
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 2546 饭卡(背包) 下一篇hdu 1042 N! 高精度运算

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C 内存管理 | 菜鸟教 (2025-12-26 20:20:37)
·如何在 C 语言函数中 (2025-12-26 20:20:34)
·国际音标 [ç] (2025-12-26 20:20:31)
·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)