zoukankan      html  css  js  c++  java
  • Magic Pen 6



    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
     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm> 
     5 
     6 using namespace std;
     7 
     8 const int N=1e5+10;
     9 
    10 long long num[N],sum[N];
    11 
    12 int main(){
    13     int n,m;
    14     while(~scanf("%d%d",&n,&m)){
    15         sum[0]=0;
    16         for(int i=1;i<=n;i++){
    17             scanf("%lld",&num[i]);
    18             sum[i]=sum[i-1]+num[i]%m;
    19         }
    20         int ans=0,flag=1;
    21         for( int i=n; i>0&&flag; i-- ){
    22             for( int j=n; j>=i; j-- ){
    23                 if((sum[j]-sum[j-i])%m==0){
    24                     ans=i;
    25                     flag=0;
    26                     break;
    27                 }
    28             } 
    29         } 
    30         cout<<ans<<endl;
    31     }    
    32     return 0;
    33 } 
    有些目标看似很遥远,但只要付出足够多的努力,这一切总有可能实现!
  • 相关阅读:
    阿里云服务器无法通过浏览器访问
    浅谈java枚举类
    WebService基础学习
    cxf报错 Cannot find any registered HttpDestinationFactory from the Bus.
    Mybatis JdbcType与Oracle、MySql 数据类型对应关系
    plsql + instantclient 连接oracle ( 超简单)
    Shiro框架
    Java中 实体类 VO、 PO、DO、DTO、 BO、 QO、DAO、POJO的概念
    POI 生成 word 文档 简单版(包括文字、表格、图片、字体样式设置等)
    web.xml 配置文件 超详细说明!!!
  • 原文地址:https://www.cnblogs.com/Bravewtz/p/10554117.html
Copyright © 2011-2022 走看看