ZOJ-3714-Java Beans

来源:互联网 发布:js打开新窗口post 编辑:程序博客网 时间:2024/05/22 01:45

有N个小孩坐在一个圆圈,他们每个人手里拿着一些java豆。 他们的老师想选择M个孩子,他们坐在M个连续的座位上,从他们那里收集java豆。


老师知道每个孩子拥有的java bean的数量,现在她想知道她可以从M连续坐的孩子获得的最大数量的java bean。 你能帮助她吗?

#include <stdio.h>#include <algorithm>#include <iostream>#include <string.h>#include <stdlib.h>#include <queue>#include <vector>#include <math.h>#include <stack>#include <map>#define rtl rt<<1#define rtr rt<<1|1typedef long long LL;using namespace std;const int MAX = 200+10;const double eps = 1e-10;const double PI = acos(-1.0);int t, n, m, a[MAX];int main(){   scanf("%d", &t);   int cnt, ans;   while(t--)   {       cin>>n>>m;       ans = 0;       for(int i = 0; i<n; ++i)        scanf("%d", &a[i]);       for(int i = 0; i<n; ++i)       {           cnt = 0;           for(int j = 0; j<m; ++j)           {               int k = (i+j)%n;               cnt+=a[k];           }           if(cnt>ans)ans = cnt;       }       cout<<ans<<endl;   }    return 0;}


0 0
原创粉丝点击