hdu 4648 Magic Pen
来源:互联网 发布:java破解版下载 编辑:程序博客网 时间:2024/06/05 15:00
Magic Pen 6
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)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 31 63 32 3 62 51 3
Sample Output
120HintThe magic pen can be used only once to scratch out consecutive students.
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100005int a[N];long long sum[N];int main(){ int n,m,i,j,mod,max; while(~scanf("%d%d",&n,&m)) { for(i=0;i<=N;i++) sum[i]=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum[i]=a[i]%m+sum[i-1]; }int flag=0;max=0; for(i=n;i>=0;i--){for(j=n;j>=i;j--){if((sum[j]-sum[j-i])%m==0){flag=1;max=i;break;}}if(flag)break;} printf("%d\n",max); } return 0;}
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100005int a[N];struct node{ long long sum; int id;}s[N];bool comp(node s1,node s2){ if(s1.sum==s2.sum) return s1.id<s2.id; else return s1.sum<s2.sum;}int main(){ int i,n,m,p; while(~scanf("%d%d",&n,&m)) { for(i=0;i<=N;i++) s[i].sum=0; s[0].id=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); s[i].sum=(a[i]+s[i-1].sum)%m; while(s[i].sum<0) s[i].sum+=m; s[i].id=i; } sort(s,s+n+1,comp); int max=0; for(i=1,p=0;i<=n;i++) { if(s[i].sum==s[p].sum) { if(s[i].id-s[p].id>max) max=s[i].id-s[p].id; } else p=i; } printf("%d\n",max); } return 0;}
- hdu 4648 Magic Pen
- HDU 4648 magic pen
- hdu 4648 Magic Pen 6
- HDU 4648 Magic Pen 6
- hdu - 4648 - Magic Pen 6
- hdu 4648 Magic Pen 6
- HDU 4648 Magic Pen 6
- HDU 4648 Magic Pen 6
- hdu 4648Magic Pen 6
- HDU 4648 Magic Pen 6
- hdu 4648 - Magic Pen 6(“水”题)
- hdu 4648 Magic Pen 6(贪心)
- 【HDU- 4648】 Magic Pen 6 【思维 】
- 2013 多校第五场 hdu 4648 Magic Pen 6
- hdu 4648 Magic Pen 6 多校的一个题目
- hdoj 4648 Magic Pen 6
- hdu 4649 Magic Pen 6 解题报告
- magic pen!
- struts2必需的五个jar包
- C++容器详解
- jQuery怎么解析Json字符串
- ios之作品上传到App Store的流程
- Android新浪微博客户端(四)——添加多个账户及认证
- hdu 4648 Magic Pen
- 在Tomcat 与weblogic 中的 日志(log4j) 配置系列三(log文件的存放路径)
- jsp写的登录页面用户名和密码
- python 从姐脱吧下载妹子图片
- 静态成员函数调用非静态成员变量
- 基于Windows XP下的USB驱动开发总结
- jsp点击按钮数字自增功能
- Spring MVC 教程,快速入门,深入分析
- 程序员喝酒的计算机文化