zoukankan      html  css  js  c++  java
  • HDU 4648 Magic Pen 6 (。。。。。。。。。。)

    Magic Pen 6

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


    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
     
    Recommend
    zhuyuanchen520
     

     这题不解释。。。。。。。。。。。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    const int N=100010;
    
    long long num[N],sum[N];
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int n,m;
        while(~scanf("%d%d",&n,&m)){
            sum[0]=0;
            for(int i=1;i<=n;i++){
                scanf("%lld",&num[i]);
                sum[i]=sum[i-1]+num[i]%m;
            }
            int ans=0,flag=1;
            for(int i=n;i>0 && flag;i--)
                for(int j=n;j>=i;j--)
                    if((sum[j]-sum[j-i])%m==0){
                        ans=i;
                        flag=0;
                        break;
                    }
            printf("%d
    ",ans);
        }
        return 0;
    }

    下面是我比赛用的方法,可是当时不知脑子哪里出现问题了,总WA,服了自己了,现在AC了:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    
    using namespace std;
    
    const int N=10010;
    
    int n,m,sum[100010];
    vector<int> vt[N];
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        while(~scanf("%d%d",&n,&m)){
            sum[0]=0;
            for(int i=0;i<N;i++)
                vt[i].clear();
            vt[0].push_back(0);     //不能用vt[0][0]=0;!!!!!!!!!!
            int x;
            for(int i=1;i<=n;i++){
                scanf("%d",&x);
                sum[i]=(sum[i-1]+x%m+m)%m;
                vt[sum[i]].push_back(i);
            }
            int ans=0;
            for(int i=0;i<N;i++){
                int len=vt[i].size();
                if(len>=2){
                    int tmp=vt[i][len-1]-vt[i][0];
                    if(ans<tmp)
                        ans=tmp;
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    数据结构实践——败者树归并模拟
    systemctl介绍
    Andriod Atom x86模拟器启动报错。
    (白书训练计划)UVa 11572 Unique Snowflakes(窗体滑动法)
    OpenCV2.3.1在CentOS6.5下的安装
    本学期课程教学要解决这个问题要点备忘录
    firefox浏览器和IE
    [LeetCode] Validate Binary Search Tree
    android性能优化优秀文章
    如何在使用eclipse的情况下,清理android项目中的冗余class文件和资源文件以及冗余图片
  • 原文地址:https://www.cnblogs.com/jackge/p/3242309.html
Copyright © 2011-2022 走看看