zoukankan      html  css  js  c++  java
  • 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
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 #include <iostream>
     5 #include <algorithm>
     6 #include <cmath>
     7 #include <set>
     8 #include <queue>
     9 #include <stack>
    10 #include <map>
    11 #include <vector>
    12 using namespace std;
    13 typedef long long ll;
    14 typedef unsigned long long ull;
    15 typedef pair<int, int> P;
    16 int a[200];
    17 bool cmp(const int &a,const int &b)
    18 {
    19     return a>b;
    20 }
    21 int main()
    22 {
    23     int t;
    24     int n,m,i,j,k;
    25     int a[205];
    26     scanf("%d",&t);
    27     while(t--)
    28     {
    29         int b[205]={0};
    30         scanf("%d%d",&n,&m);
    31         for(i=0;i<n;i++)
    32             scanf("%d",&a[i]);
    33 
    34         for(i=0;i<n;i++)
    35         {
    36             for(j=i,k=0;j<n+1,k<m;j++,k++)
    37             {
    38                 if(j==n)
    39                     j=0;
    40                     b[i]+=a[j];
    41             }
    42         }
    43         sort(b,b+n);
    44        printf("%d
    ",b[n-1]);
    45     }
    46     return 0;
    47 }
    View Code
    #include<stdio.h>
    int d[210];
    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=0;i<n;i++)
                scanf("%d",&d[i]);
                
                max=0;
                for(i=0;i<n;i++)
                {
                    sum=0;//注意复位
                    for(j=i;j<i+m;j++)
                    sum+=d[j%n];
                    if(max<sum)
                        max=sum;
                }
                printf("%d
    ",max);
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    spark内存管理这一篇就够了
    spark推测机制及参数设置
    python易错点汇总,不定期更新
    Spark架构与原理这一篇就够了
    MySQL查询这一篇就够了
    pyspark计算最大值、最小值、平均值
    Spark性能调优的方法
    大流量场景下MySQL如何准备
    100台CentOS7要分区怎么办?
    100台CentOS7要升级OpenSSH怎么办?
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7246769.html
Copyright © 2011-2022 走看看