http://acm.nyist.net/JudgeOnline/problem.php?pid=709
Irregular egg time limit: +Ms | Memory Limit:65535KB Difficulty:2
-
-
Describe
-
We explore the universe to understand the wonders of the starry sky, but we are seldom aware of the dangers of hiding in the depths of the universe, staring at our earth all the while. If aliens visit us, the results may not be the same as when Columbus was on the American continent, which is history and reality.
The dormant irregular eggs found on the planet ZDM-777, whose appearance is different from the common eggs, are covered with a layer of graphite. When the person approached, the layer of graphite began to melt, can see the inside of the alien eggs are moving, irregular eggs are living things, with some heat or pressure sensor these basic central nervous system, by perceiving the heat around, select the maximum parasitic heat. However, if the surrounding area is not suitable for the parasite, irregular eggs will choose to sleep.
The surrounding heat can be expressed by a string of integers a1,a2,......, An, the irregular eggs have a certain length of L, the irregular eggs are always selected ai+ai+1+...+ai+l-1 to reach the maximum value of parasitic. If the surrounding heat is less than 0, the irregular eggs are selected for hibernation.
How does an irregular egg perceive its parasitic place? We explore the universe to understand the wonders of the starry sky, but we are seldom aware of the dangers of hiding in the depths of the universe, staring at our earth all the while. If aliens visit us, the results may not be the same as when Columbus was on the American continent, which is history and reality.
The dormant irregular eggs found on the planet ZDM-777, whose appearance is different from the common eggs, are covered with a layer of graphite. When the person approached, the layer of graphite began to melt, can see the inside of the alien eggs are moving, irregular eggs are living things, with some heat or pressure sensor these basic central nervous system, by perceiving the heat around, select the maximum parasitic heat. However, if the surrounding area is not suitable for the parasite, irregular eggs will choose to sleep.
The surrounding heat can be expressed by a string of integers a1,a2,......, An, the irregular eggs have a certain length of L, the irregular eggs are always selected ai+ai+1+...+ai+l-1 to reach the maximum value of parasitic. If the surrounding heat is less than 0, the irregular eggs are selected for hibernation.
How does an irregular egg perceive its parasitic place?
-
Input
-
First line: K indicates how many sets of test data are available.
Next, there are 2 rows for each set of test data, line 1th: L N
Line 2nd: A1 A2 ... an
"Constraint conditions"
2≤k≤5 L≤n, 1≤l≤10 1≤n≤1000-100≤ai≤100
There is a space between the data.
-
Output
-
For each set of test data, the output line: The starting position of the parasitic eggs can be. If there are multiple parasitic, select a small starting position. If there is nowhere to parasitic, then output 0.
-
Sample input
-
530 0 100-30 1003 5-100 80-80-100 80
-
Sample output
-
30
-
Source
-
sixth session of Henan Province Program design Competition
/* Test Instructions: Is the maximum continuous sub-sequence of length L, the output starting point
Method One:
#include <stdio.h> #include <string.h> #define INF 0x3f3f3f3fint Main () {int n,l;int a[1010];int res[1010]; int t;scanf ("%d", &t), while (t--) {scanf ("%d%d", &l, &n), memset (res,-inf, sizeof (RES)), and for (int i = 1; I <= n ; ++i) {scanf ("%d", a+i);} int s = 0; for (int i = 1; I <= n; ++i) {if (i<l) s + = A[i];else{s + = A[i];res[i] = s;s-= a[i-l+1];}} int max=-inf;int pos;for (int i = l; I <= n; ++i) {if (Max<res[i]) {max = res[i];p os=i;}} if (max<0) printf ("0\n"), Else printf ("%d\n", pos-l+1);} return 0;}
Method Two:
#include <cstdio> #include <cstring>int a[1100];int n,l;int main () { int t,temp;; scanf ("%d", &t); while (t--) { int sum=0; scanf ("%d%d", &l, &n); for (int i=1;i<=n;i++) { scanf ("%d", &temp); Sum+=temp; a[i]=sum; } int maxn=0; int k=0; for (int i = 1; I <= n-l+1; i++) { int s = a[i+l-1]-a[i-1]; if (S > Maxn) { maxn=s; k=i; } } printf ("%d\n", k); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Alien Egg 709 Nanyang OJ