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) ...
随机推荐
- Hadoop:开发机运行spark程序,抛出异常:ERROR Shell: Failed to locate the winutils binary in the hadoop binary path
问题: windows开发机运行spark程序,抛出异常:ERROR Shell: Failed to locate the winutils binary in the hadoop binary ...
- [Python]多线程入门
原文:http://blog.csdn.net/ice110956/article/details/28421807 Python的多线程有两种实现方法: 函数,线程类 1.函数 调用thread模块 ...
- pip通过requirements.txt安装依赖
pip install -t . -r requirements.txt requirements.txt Keras==2.0.8 gensim torchvision opencv-python ...
- DevExpress去除多国语言包
DevExpress作为windows开发中较为强大的第三方组件,能极大的提高编程效率和界面效果.但也要引用它较多的dll文件,它专门有个查看dll程序集依赖的工具,在VS的工具菜单下: 在VS的工具 ...
- LintCode: Identical Binary Tree
C++ /** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; ...
- NetCore中使用DynamicExpresso、Z.Expressions、LambdaParser进行安字符串求值
例子如下: Z.Expressions从2.0开始支持了NetCore,但是收费的.其它两者免费.建议使用DynamicExpresso,免费而且速度快.LambdaParser目前支持太少. sta ...
- SqlServer和Mysql插入记录前判断是否存在,存在则插入,不存在则修改。
SqlServer中是这样: ) ,@title,@searchKeys,@serviceIntervalSecond,@sleepMillisecondPerSearch) ELSE UPDATE ...
- 低危漏洞- X-Frame-Options Header未配置
原文链接:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/X-Frame-Options?redirectlocale=en-US&redi ...
- java获取cpu、内存、硬盘信息[转]
http://m.oschina.net/blog/312911 1 下载安装sigar-1.6.4.zip 使用java自带的包获取系统数据,容易找不到包,尤其是内存信息不够准确,所以选择使用sig ...
- MySQL配置文件my.ini参数注释说明
mysqld程序--目录和文件basedir = path 使用给定目录作为根目录(安装目录).character-sets-dir = path 给出存放着字符集的目录.datadir = path ...