ZCMU训练赛-J(循环节+字符串处理)
J - Java Beans
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand. Their teacher want to select M kids who seated in M consecutive seats and collect java beans from them.
The teacher knows the number of java beans each kids has, now she wants to know the maximum number of java beans she can get from Mconsecutively seated kids. Can you help her?
Input
There are multiple test cases. The first line of input is an integer T indicating the number of test cases.
For each test case, the first line contains two integers N (1 ≤ N ≤ 200) and M (1 ≤ M ≤ N). Here N and M are defined in above description. The second line of each test case contains Nintegers Ci (1 ≤ Ci ≤ 1000) indicating number of java beans the ith kid have.
Output
For each test case, output the corresponding maximum java beans the teacher can collect.
Sample Input
2
5 2
7 3 1 3 9
6 6
13 28 12 10 20 75
Sample Output
16
158
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
int a[];
bool cmp(const int &a,const int &b)
{
return a>b;
}
int main()
{
int t;
int n,m,i,j,k;
int a[];
scanf("%d",&t);
while(t--)
{
int b[]={};
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%d",&a[i]); for(i=;i<n;i++)
{
for(j=i,k=;j<n+,k<m;j++,k++)
{
if(j==n)
j=;
b[i]+=a[j];
}
}
sort(b,b+n);
printf("%d\n",b[n-]);
}
return ;
}
#include<stdio.h>
int d[];
int main(int argc, char* argv[])
{
int t,i,j;
int n,m,sum,max;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%d",&d[i]); max=;
for(i=;i<n;i++)
{
sum=;//注意复位
for(j=i;j<i+m;j++)
sum+=d[j%n];
if(max<sum)
max=sum;
}
printf("%d\n",max);
}
}
return ;
}
ZCMU训练赛-J(循环节+字符串处理)的更多相关文章
- ZCMU训练赛-H(模拟)
H - Hard to Play MightyHorse is playing a music game called osu!. After playing for several months ...
- ZCMU训练赛-A(模拟)
A - Applications https://vjudge.net/contest/174208#overview Recently, the ACM/ICPC team of Marjar Un ...
- ZCMU训练赛-B(dp/暴力)
B - Break Standard Weight The balance was the first mass measuring instrument invented. In its tradi ...
- hdu 4333"Revolving Digits"(KMP求字符串最小循环节+拓展KMP)
传送门 题意: 此题意很好理解,便不在此赘述: 题解: 解题思路:KMP求字符串最小循环节+拓展KMP ①首先,根据KMP求字符串最小循环节的算法求出字符串s的最小循环节的长度,记为 k: ②根据拓展 ...
- poj 2406 Power Strings【字符串+最小循环节的个数】
Po ...
- Uvalive - 3026 Period (kmp求字符串的最小循环节+最大重复次数)
参考:http://www.cnblogs.com/jackge/archive/2013/01/05/2846006.html 总结一下,如果对于next数组中的 i, 符合 i % ( i - n ...
- KMP解决字符串最小循环节相关问题
经典问题 : 给出一个由某个循环节构成的字符串,要你找出最小的循环节,例如 abababab 最小循环节当是 ab ,而类似 abab 也可以成为它的循环节,但并非最短. 分析 : 对于上述问题有两个 ...
- HDU 3746 (KMP求最小循环节) Cyclic Nacklace
题意: 给出一个字符串,要求在后面添加最少的字符是的新串是循环的,且至少有两个循环节.输出最少需要添加字符的个数. 分析: 假设所给字符串为p[0...l-1],其长度为l 有这样一个结论: 这个串的 ...
- Period(KMP,循环节问题)
题意: 求给你个串,前i位子串由某个字符串重复k次得到,求所有的i和k 分析: i-next[i]恰好是一个循环节 #include <map> #include <set> ...
随机推荐
- 【bzoj3196】Tyvj 1730 二逼平衡树 线段树套Treap
题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在区间内的前驱(前驱定义 ...
- JavaScript获取访问设备信息
<html xmlns=http://www.w3.org/1999/xhtml> <head> <title>JavaScript获取访问设备信息</tit ...
- [SCOI2010]序列操作 线段树
---题面--- 题解: 在考场上打的这道题,出人意料的很快就打完了?! 直接用线段树,维护几个东西: 1,lazy标记 : 表示区间赋值 2,mark标记:表示区间翻转 3,l1:前缀最长连续的1的 ...
- bzoj进度条
好久没发进度了 这个月没有上个月那么猛,肯能使因为这个月不想水题吧 No. 510 Solved Problems List Solved 368 10001001100210071008101210 ...
- chrome 不支持12px以下字体为题的解决
现英文9px 设置 在chrome 下无效,可以通过 -webkit-transform: scale(0.75); 12*0.75 =9 得到小字体(在chrome浏览器下 大小缩放到0.75倍) ...
- IOI1998 Polygon [区间dp]
[IOI1998]Polygon 题意翻译 题目可能有些许修改,但大意一致 多边形是一个玩家在一个有n个顶点的多边形上的游戏,如图所示,其中n=4.每个顶点用整数标记,每个边用符号+(加)或符号*(乘 ...
- HDU1859 最小长方形 (水
最小长方形 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- Spring中Resource接口的前缀书写格式
Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt"); //这个 ...
- 获取系统内RAR安装路径
RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVers ...
- Python学习笔记 - day5 - 文件操作
Python文件操作 读写文件是最常见的IO操作,在磁盘上读写文件的功能都是由操作系统提供的,操作系统不允许普通的程序直接操作磁盘(大部分程序都需要间接的通过操作系统来完成对硬件的操作),所以,读写文 ...