Hdoj title 4648 Magic Pen 6 (water problem)

Source: Internet
Author: User

Magic Pen 6Time limit:2000/1000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 1964 Accepted Submission (s): 682


Problem DescriptionIn hit, many people has a magic pen. Lilu0355 has a magic pen, darkgt have 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 is the timer's friends, and timer doesn ' t want to see them fail the course. So, the Timer decides to the use of his magic pen to scratch out consecutive names as much as possible. However, teacher have already calculated the sum of all students ' scores module M. Then in order the teacher find anything strange, Timer should keep the sum of the rest of students ' scores Modu Le M the same.

Plans can never keep pace with changes, Timer was too busy to do this job. Therefore, he turns to you. He needs the "save" these students as much as possible.
Inputthere is multiple test cases.
The first line of each case contains both integer N and M, (0< N <= 100000, 0 < M < 10000), then followed by a l INE consists of N integers a1,a2,... an ( -100000000 <= a1,a2,... a <= 100000000) denoting the score of each student. ( Strange score? Yes, in great hits, everything is possible)

Outputfor 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
HintThe Magic pen can used only once to scratch out consecutive students.

Source2013 multi-university Training Contest 5
Recommendzhuyuanchen520 | We have carefully selected several similar problems for you:5193 5192 5191 5190 5189 AC Code
#include <stdio.h> #include <string.h>int sum[100010],a[100010];int n,m;int main () {while (scanf ("%d%d", &N,&M)!=eof) {int i,j;memset (sum,0,sizeof (sum)), for (i=1;i<=n;i++) {scanf ("%d", &a[i]); sum[i]=sum[ I-1]+a[i];} int Ans=0,flag=0;for (i=n;i>=1;i--) {for (j=1;j+i-1<=n;j++) {int temp= (sum[j+i-1]-sum[j-1])%m;if (!temp) {ans=i; Flag=1;break;}} if (flag) break;} printf ("%d\n", ans);}}


Hdoj title 4648 Magic Pen 6 (water problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.