ZOJ3714: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 M consecutively 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 N integers 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
题意:很简单,给出n,k,计算n个数中长度为k的最大和,而且其中没有负数,只需要注意这些数字组成的是一个环形
思路:数据很小,直接水过
#include <stdio.h>
#include <string.h> int main()
{
int t,n,k,i,j,a[405],sum,MAX;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
a[n+i] = a[i];
}
MAX = 0;
for(i=1; i<=n; i++)
{
sum = 0;
for(j = i; j<i+k; j++)
{
sum+=a[j];
}
if(sum>MAX)
MAX = sum;
}
printf("%d\n",MAX);
}
return 0;
}
ZOJ3714:Java Beans的更多相关文章
- 黑马程序员:Java基础总结----JavaBean 内省
黑马程序员:Java基础总结 JavaBean 内省 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! JavaBean 内省 软件包 java.beans 包含与开 ...
- java beans
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- [ACM_水题] ZOJ 3714 [Java Beans 环中连续m个数最大值]
There are N little kids sitting in a circle, each of them are carrying some java beans in their hand ...
- java.lang.ClassCastException: sun.jdbc.odbc.JdbcOdbcStatement cannot be cast to java.beans.Statement
当导入的包为:import java.sql.Statement;时,无任何错误 当导入的包为:import java.beans.Statement;时,出错
- Java基础知识强化99:Java 常见异常及趣味解释
常见 Java 异常解释:(译者注:非技术角度分析.阅读有风险,理解需谨慎:) 1. java.langjava.lang软件包是java语言的核心部分,它提供了java中的基础类. java.lan ...
- 深入理解Java类加载器(1):Java类加载原理解析
1 基本信息 每个开发人员对Java.lang.ClassNotFoundExcetpion这个异常肯定都不陌生,这背后就涉及到了java技术体系中的类加载.Java的类加载机制是技术体系中比较核心的 ...
- SQLException: com.mchange.v2.c3p0.ComboPooledDataSource [ java.beans.IntrospectionException: java.lang.reflect.InvocationTargetException [numThreadsAwaitingCheckoutDefaultUser] ] has been closed()
问题:Could not get JDBC Connection; nested exception is java.sql.SQLException: com.mchange.v2.c3p0.Com ...
- Spring3.2 Contorller单元测试参数问题: java.lang.NoSuchMethodException
使用3.2做单元测试的时候发现这个问题,因为之前都是用3.0中的配置适配器使用AnnotationMethodHandlerAdapter,到3.2中升级为RequestMappingHandlerA ...
- 沉淀,再出发:Java基础知识汇总
沉淀,再出发:Java基础知识汇总 一.前言 不管走得多远,基础知识是最重要的,这些知识就是建造一座座高楼大厦的基石和钢筋水泥.对于Java这门包含了编程方方面面的语言,有着太多的基础知识了,从最初的 ...
随机推荐
- 谜一样的jquery之$选择器
jquery是一个强大的js类库,提供了很多便利的操作方法并兼容不同的浏览器,一旦使用便欲罢不能,根本停不下来,今天我们就来解读一下这个神秘的jquery源代码. 前几天思考再三,自己尝试着封装了一下 ...
- yii2 memcache 跨平台交互 键和值不一样
1 首先在配置文件中加载 web\basic\config\web.php ........ 'components' => [ 'request' => [ // !!! insert ...
- 黄聪:wordpress如何防止发布文章时候自动清除<P>、<br>换行标签
1.安装[TinyMCE Advanced]插件 2.进入[后台]--[设置]--[TinyMCE Advanced]把这个选项勾上保存即可.
- 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误
解决办法:使用for循环,而不是foreach循环 例如: ArrayList akeys=new ArrayList(_transmit_tb.Keys); ;p> -;p--) { _tra ...
- Vue 目录结构分析 数据绑定 绑定属性 循环渲染数据 数据渲染
一.目录结构分析 node_modules 项目所需要的各种依赖 src 开发用的资源 assets 静态资源文件 App.vue 根组件 main.js 配置路由时会用 .babelrc 配置文件 ...
- MongoDB内嵌文档操作
实体定义: [BsonIgnoreExtraElements] public class Person : BaseEntity { public string FirstName { get; se ...
- 文件os.path相关方法
#!/usr/bin/python3# -*- coding: utf-8 -*-# @Time : 2018/6/13 15:03# @File : abspath_1.py impor ...
- web开发,click,touch,tap事件浅析
一.click 和 tap 比较 两者都会在点击时触发,但是在手机WEB端,click会有 200~300 ms,所以请用tap代替click作为点击事件. singleTap和doubleTap 分 ...
- windows拖动文件到Ubuntu
只需要安装 sudo apt install lrzsz
- django-渲染页面+locals
from django.shortcuts import render, redirect from django.views import View from django.http import ...