Program design competition for the sixth college student in Henan province

Source: Internet
Author: User

Alien eggs

Time Limit: 1 Second Memory Limit: 64 MB

Description

We explore the universe to understand the mysteries of the vast starry sky, but we are rarely aware of the dangers of hiding in the depths of the universe, they are always staring at our Earth. If aliens visit us, the result may not be the same as that of Columbus when he stepped onto the continent of America. This is a historical and realistic situation.
The dormant alien eggs found on the planet ZDM-777, whose appearance is different from the common eggs and whose surface is covered by a layer of graphite. When a person approaches, the graphite layer begins to melt, and the shaped eggs inside are active. The shaped eggs are active and have some heat or pressure sensors, which are the basic central nervous system, by perceiving the surrounding heat, you can select the maximum parasitic heat. However, if there are not suitable parasitic locations around, the alien eggs choose to sleep.
You can use a string of integers a1, a2 ,......, According to an, exclusive eggs have a certain length of L, and exclusive eggs always choose ai + 1 +... + Ai + L-1 reach the maximum parasitic position. If the surrounding heat is less than 0, the alien eggs choose sleep.
How does an alien egg perceive its parasitic locations?

Input

Row 1: K indicates the number of groups of test data.
Next, there will be 2 rows of test data in each group, 1st rows: L N
Row 3: a1 a2 ...... AN

2 ≤ K ≤ 5 L ≤ N, 1 ≤ L ≤ 10 1 ≤ N ≤ 1000-100 ≤ ai ≤ 100
There is a space between data.

Output

For each group of test data, the output line is the starting position where the alien egg can be parasitic. If there are multiple hosts that can be parasitic, select a small starting position. If there is nowhere to be parasitic, 0 is output.

Sample Input

23 530 0 100-30 1003 5-100 80-80-100 80

Sample Output

30

Source

Henan Sixth College student program design competition



The provincial water question, but it was still wrong twice, alas :-(

Code:

# Include <cstdio> # include <cstring> # include <cstdlib> # include <cmath> # include <algorithm> # include <string> using namespace std; int main () {int K, L, N, a [1, 1005]; scanf ("% d", & K); while (K --) {scanf ("% d ", & L, & N); for (int I = 1; I <= N; I ++) {scanf ("% d", & a [I]);} int ans, sum = 0; for (int I = 1; I <= L; I ++) {sum + = a [I];} if (sum> = 0) ans = 1; else ans = 0; int tmp = sum; for (int I = L + 1; I <= N; I ++) {sum-= a [I-L]; sum + = a [I]; if (sum> tmp & sum> = 0) {ans = I-L + 1; tmp = sum ;}} printf ("% d \ n", ans);} return 0 ;}


The above idea is a bit confusing. It's just a few days away!

Paste another (transfer ):

# Include <iostream> # include <string> # include <algorithm> # include <vector> # include <sstream> # include <cstring> # include <math. h> # include <stdio. h ># include <map ># include <set> # include <stack> using namespace std; int main () {int t, I, l, n; int pos [1010], tmp; cin> t; while (t --) {cin> l> n; pos [0] = 0; for (I = 1; I <= n; I ++) {cin> tmp; pos [I] = pos [i-1] + tmp;} int ans =-1, idx = 0; for (I = l; I <= n; I ++) {if (pos [I]-pos [I-l]> ans) {ans = pos [I]-pos [I-l]; idx = I-l + 1 ;}} printf ("% d \ n", idx );} return 0 ;}


Program design competition for the sixth college student in Henan province

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.