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): 582 Accepted Submission(s): 224
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.
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)
1 6
3 3
2 3 6
2 5
1 3
2
0
The magic pen can be used only once to scratch out consecutive students.
这题不解释。。。。。。。。。。。
#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 (。。。。。。。。。。)的更多相关文章
- hdu 4648 - Magic Pen 6(“水”题)
摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...
- HDU 4648 Magic Pen 6
题目链接 6Y什么水平.. #include <cstdio> #include <cstring> #include <string> #include < ...
- HDU 4648 Magic Pen 6 思路
官方题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- hdu 4946 Area of Mushroom (凸包,去重点,水平排序,留共线点)
题意: 在二维平面上,给定n个人 每个人的坐标和移动速度v 若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点) 则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 , ...
- HDU 4605 Magic Ball Game(可持续化线段树,树状数组,离散化)
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4605 Magic Ball Game (dfs+离线树状数组)
题意:给你一颗有根树,它的孩子要么只有两个,要么没有,且每个点都有一个权值w. 接着给你一个权值为x的球,它从更节点开始向下掉,有三种情况 x=w[now]:停在此点 x<w[now]:当有孩子 ...
- HDU 4602 Magic Ball Game(离线处理,树状数组,dfs)
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
随机推荐
- win7下使用Taste实现协同过滤算法
如果要实现Taste算法,必备的条件是: 1) JDK,使用1.6版本.需要说明一下,因为要基于Eclipse构建,所以在设置path的值之前要先定义JAVA_HOME变量. 2) Maven,使用2 ...
- (转)在NGUI使用图片文字(数字、美术字)(直接可用于UILable)
本文永久地址:http://www.omuying.com/article/24.aspx,[文章转载请注明出处!] 在 Unity 开发过程中,我们经常会使用到美术提供的图片文字(数字)来美化我们的 ...
- 'Lock wait timeout exceeded; try restarting transaction'问题
OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction') 原因很简单,太多错误,意外处理没有 ...
- LInux 解压缩文件
常用命令有2个,一个是tar,一个是zip,二选一就行 有的服务器没有安装zip命令,就只有tar可以用,我个人建议还是安装一个zip好一些,tar实在太繁琐 1.解压 tar -zxvf ./xxx ...
- Log4j日志体系结构
转自:https://my.oschina.net/andylucc/blog/794867 摘要 我们在写日志的时候首先要获取logger,在每一个使用log4j的项目都有很多个地方要获取logge ...
- WDCP安装可选组件的快捷命令
memcache的安装 wget -c http://down.wdlinux.cn/in/memcached_ins.sh chmod 755 memcached_ins.sh ./memcache ...
- HTTPS 原理与证书实践
1.1 网络安全知识 1.1.1 网结安全出现背景 网络就是实现不同主机之间的通讯,网络出现之初利用TCP/IP协议簇的相关协议概念,已经满足了互连两台主机之间可以进行通汛的目的,虽然看似简简单单几句 ...
- oracle v$sqlarea 分析SQL语句使用资源情况 确认是否绑定变量
-如何确定系统中是否存在绑定变量的情况:首先创建一个表,用于存放整理过得数据:create table t1 as select sql_text from v$sqlarea;----V$SQLAR ...
- robot framework-requests库安装过程问题解决
这几天本想研究下用robotframework+HTTP library (Requests)来做接口测试(http协议), 安装完Requests库后,在RIDE里导入该库时显示是红色,即导入失败( ...
- Python取得系统进程列表
一.上代码 import psutil for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs=['pid', 'name ...