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=; long long num[N],sum[N]; int main(){ //freopen("input.txt","r",stdin); int n,m;
while(~scanf("%d%d",&n,&m)){
sum[]=;
for(int i=;i<=n;i++){
scanf("%lld",&num[i]);
sum[i]=sum[i-]+num[i]%m;
}
int ans=,flag=;
for(int i=n;i> && flag;i--)
for(int j=n;j>=i;j--)
if((sum[j]-sum[j-i])%m==){
ans=i;
flag=;
break;
}
printf("%d\n",ans);
}
return ;
}

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

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector> using namespace std; const int N=; int n,m,sum[];
vector<int> vt[N]; int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d",&n,&m)){
sum[]=;
for(int i=;i<N;i++)
vt[i].clear();
vt[].push_back(); //不能用vt[0][0]=0;!!!!!!!!!!
int x;
for(int i=;i<=n;i++){
scanf("%d",&x);
sum[i]=(sum[i-]+x%m+m)%m;
vt[sum[i]].push_back(i);
}
int ans=;
for(int i=;i<N;i++){
int len=vt[i].size();
if(len>=){
int tmp=vt[i][len-]-vt[i][];
if(ans<tmp)
ans=tmp;
}
}
printf("%d\n",ans);
}
return ;
}

HDU 4648 Magic Pen 6 (。。。。。。。。。。)的更多相关文章

  1. hdu 4648 - Magic Pen 6(“水”题)

    摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...

  2. HDU 4648 Magic Pen 6

    题目链接 6Y什么水平.. #include <cstdio> #include <cstring> #include <string> #include < ...

  3. HDU 4648 Magic Pen 6 思路

    官方题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...

  4. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. hdu 1754 I Hate It (线段树功能:单点更新和区间最值)

    版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...

  6. hdu 4946 Area of Mushroom (凸包,去重点,水平排序,留共线点)

    题意: 在二维平面上,给定n个人 每个人的坐标和移动速度v 若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点) 则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 , ...

  7. HDU 4605 Magic Ball Game(可持续化线段树,树状数组,离散化)

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. HDU 4605 Magic Ball Game (dfs+离线树状数组)

    题意:给你一颗有根树,它的孩子要么只有两个,要么没有,且每个点都有一个权值w. 接着给你一个权值为x的球,它从更节点开始向下掉,有三种情况 x=w[now]:停在此点 x<w[now]:当有孩子 ...

  9. HDU 4602 Magic Ball Game(离线处理,树状数组,dfs)

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

随机推荐

  1. 斯坦福深度学习与nlp第四讲词窗口分类和神经网络

    http://www.52nlp.cn/%E6%96%AF%E5%9D%A6%E7%A6%8F%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E4%B8%8Enlp%E7%A ...

  2. MySQL 百万级分页优化(Mysql千万级快速分页)(转)

    http://www.jb51.net/article/31868.htm 以下分享一点我的经验 一般刚开始学SQL的时候,会这样写 复制代码 代码如下: SELECT * FROM table OR ...

  3. 原:wireshare使用技巧收集

    /data/local/tcpdump -p -vv -s 0 -w /sdcard/ThinkDrive.pcap     先抓一个pcap的包. 1. 查看所有的链接与流量 统计->对话 这 ...

  4. yield python

    原文:http://pyzh.readthedocs.io/en/latest/the-python-yield-keyword-explained.html 3. (译)Python关键字yield ...

  5. MFC中调用web api

    使用COM组件来调用,需要catch com error. IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL; BSTR bstrString = NULL; HR ...

  6. $(...).modal is not a function

    bootstrap中调用$(...).modal 方法 提示一个错误 is not a function 检查HTML结构发现,是因为使用了多个Jquery版本,产生了冲突. 解决办法:删掉一个Jqu ...

  7. OpenGL ES 3.0 图元组合和光栅化(三)

    图元是能够被OpenGL ES 绘制的几何物体,如三角形.线条或者精灵.在图元组合过程 中,对每个图元必须判断是否位于投影 截体内,如果图元不完全在平截体内部,将被视图平截体剪贴,如果完全在平截体外, ...

  8. vCenter Server Virtual Appliance features and benefits

    http://vmwire.com/tag/vcsa/ Installed on SUSE Linux Enterprise Server 11 x64. OVF when deployed is c ...

  9. C#或Python中正则表达式元字符含意

    一.列表 元字符 描述 \ 将下一个字符标记为一个特殊字符.或一个原义字符.或一个 向后引用.或一个八进制转义符.例如,'n' 匹配字符 "n".'\n' 匹配一个换行符.序列 ' ...

  10. cpu内存访问速度,磁盘和网络速度,所有人都应该知道的数字

    google 工程师Jeff Dean 首先在他关于分布式系统的ppt文档列出来的,到处被引用的很多. 1纳秒等于10亿分之一秒,= 10 ^ -9 秒  ---------------------- ...