HDOJ 题目4648 Magic Pen 6(水题)

Magic Pen 6

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 1964    Accepted Submission(s): 682

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   |   We have carefully selected several similar problems for you:  5193 5192 5191 5190 5189

ac代码

#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);
	}
}
时间: 2024-12-21 16:35:50

HDOJ 题目4648 Magic Pen 6(水题)的相关文章

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): 2057    Accepted Submission(s): 706 Problem Description In HIT, many people have a magic pen. Lilu0355 has a magic pen, darkgt has a

HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,Java就是打表,都不能AC,因为Java的输入是流,需要的时间比C真的长好多.... Problem Description You just need to calculate the sum of the formula: 1^2+3^2+5^2+--+ n ^2. Input In each

HDOJ/HDU 2537 8球胜负(水题.简单的判断)

Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球,如果将该颜色的7个球全部打进,则这名选手可以打黑球,如果打进则算他胜.如果在打进自己颜色的所有球之前就把黑球打进,则算输.如果选手不慎打进了对手的球,入球依然有效. 现在给出打进的球(白球除外)的顺序,以及黑球由哪方打进,你的任务是判定哪方是胜者. 假设不会有一杆同时打进一颗黑球和其他彩球. Inp

HDOJ/HDU 2561 第二小整数(水题~排序~)

Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第一行是一个整数C,表示有C测试数据: 每组测试数据的第一行是一个整数n,表示本组测试数据有n个整数(2<=n<=10),接着一行是 n个整数 (每个数均小于100); Output 请为每组测试数据输出第二小的整数,每组输出占一行. Sample Input 2 2 1 2 3 1 1 3 Sam

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

hdu4505 小Q系列故事——电梯里的爱情(水题)

Problem Description http://acm.hdu.edu.cn/showproblem.php?pid=4505 细心的同事发现,小Q最近喜欢乘电梯上上下下,究其原因,也许只有小Q自己知道:在电梯里经常可以遇到他心中的女神HR. 电梯其实是个很暧昧的地方,只有在电梯里,小Q才有勇气如此近距离接近女神,虽然觉得有点不自在,但次数多了,女神也习惯了小Q的存在,甚至熟悉到仿佛不说上句话自己也都觉得不合适了.可是,他们的谈话也仅仅限于今天天气不错啊或是你吃了吗之类的,往往在对方微笑点

HDOJ 2317. Nasty Hacks 模拟水题

Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3049    Accepted Submission(s): 2364 Problem Description You are the CEO of Nasty Hacks Inc., a company that creates small pieces of

水题 HDOJ 4716 A Computer Graphics Problem

题目传送门 1 /* 2 水题:看见x是十的倍数就简单了 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const int MAXN = 1e4 + 10; 13

水题 HDOJ 4727 The Number Off of FFF

题目传送门 1 /* 2 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const in