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> ...
随机推荐
- 【bzoj2384】[Ceoi2011]Match 特殊匹配条件的KMP+树状数组
题目描述 给出两个长度分别为n.m的序列A.B,求出B的所有长度为n的连续子序列(子串),满足:序列中第i小的数在序列的Ai位置. 输入 第一行包含两个整数n, m (2≤n≤m≤1000000). ...
- 如何在自家厨房里制作LSD
如何在自家厨房里制作LSD -------------------------------------------------------------------------------- D-麦角酸 ...
- [洛谷P4949]最短距离
题目大意:给一棵基环树,两种操作: $1\;x\;y:$把第$x$条边长度改成$y$ $2\;x\;y:$查询$x$到$y$的最短距离 题解:发现最短距离只有两种可能,第一个是树上的距离,第二种是经过 ...
- C&C++——C与C++知识点
C++知识点系列之一(转+整理) 编程时类声明后面千万不要忘了加分号,不然会出现很多错误!! c系列之一一.#include “filename.h”和#include<filename.h&g ...
- 【BZOJ 3123】 [Sdoi2013]森林 主席树启发式合并
我们直接按父子关系建主席树,然后记录倍增方便以后求LCA,同时用并查集维护根节点,而且还要记录根节点对应的size,用来对其启发式合并,然后每当我们合并的时候我们都要暴力拆小的一部分重复以上部分,总时 ...
- HttpClientUntils工具类的使用测试及注意事项(包括我改进的工具类和Controller端的注意事项【附 Json 工具类】)
HttpClient工具类(我改过): package com.taotao.httpclient; import java.io.IOException; import java.net.URI; ...
- 通过init-connect + binlog 实现MySQL审计功能
背景: 假设这么一个情况,你是某公司mysql-DBA,某日突然公司数据库中的所有被人为删了. 尽管有数据备份,但是因服务停止而造成的损失上千万,现在公司需要查出那个做删除操作的人. 但是拥有数据库操 ...
- bzoj 5092 [Lydsy1711月赛]分割序列 贪心高维前缀和
[Lydsy1711月赛]分割序列 Time Limit: 5 Sec Memory Limit: 256 MBSubmit: 213 Solved: 97[Submit][Status][Dis ...
- JAX-WS 注解
一.概述 “基于 XML 的 Web Service 的 Java API”(JAX-WS)通过使用注释来指定与 Web Service 实现相关联的元数据以及简化 Web Service 的开发.注 ...
- 浏览器 连不上网 (3):DNS 服务器问题
解决:设置一下DNS服务器的地址 步骤: 打开网络和共享中心(网络和 Internet设置)-> 更改适配器 -> 双击我们连接的 无线网(WiFi式) 或 以太网(网线式): 从出现的窗 ...