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) ...
随机推荐
- android中使用spinner组件,以key,value的方式
接着上一篇文章的内容:android中使用spinner组件 稍做修改,以key,value的方式,在实际使用中,经常需要获取的值并不一定跟显示的内容一致. 需要先添加一个对象类,用来描述key,va ...
- 牛客网-《剑指offer》-斐波那契数列
题目:http://www.nowcoder.com/practice/c6c7742f5ba7442aada113136ddea0c3 C++ class Solution { public: in ...
- LoadRunner基于HTML-based script和URL-based script方式录制的区别和各自的使用场景
一.区别: 为了更加直观的区别这两种录制方式,我们可以分别使用这两种方式录制同一场景(打开百度首页)然后进行对比,录制的代码如下: HTML-based script方式打开百度首页: Action( ...
- 1051: 手机(MOBILE)
#include <iostream> #include <iomanip> #include <cstdlib> #include <string> ...
- WebSocket【转】
1.什么是WebSocket WebSocket 是一种自然的全双工.双向.单套接字连接.使用WebSocket,你的HTTP 请求变成打开WebSocket 连接(WebSocket 或者WebSo ...
- mysql版本导致的hibernate 方言问题
今天在看hibernate视频时,看到视频上人家的hibernate.cfg.xml配置文件在配置hibernate方言时,发现视频上是这样写的<property name="dial ...
- Maven项目继承与聚合
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6628534.html 一:继承 在Java编程中,如果多个类都使用到了相同的内容.方法时,我们可以用继承的方 ...
- Java中的List
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6538256.html Java中常用的List子类主要有:ArrayList.LinkedList.Vecto ...
- PgSql备份pg_dump与还原手记pg_restore
真没有想到,以前一直是PostgreSQL使用者,突然需要库移植又成了头一招了!原来它与mysql命令行操作区别还挺大.不用怕,但绝对要细心,因为数据库操作是网站的核心,一旦出现损坏或丢失,后果就非常 ...
- 妙用Pixel bender执行复杂运算/普通数据运算 传递Vector数组
最近发现pixel bender有两个特殊点: 1.Input Image4,不单单可以用BitmapData来初始化,也可以用Vector.<Number>初始化. 2.ShaderJo ...