KoddiOA #2
Bird Placing Sticks
简单可在线判题
考点(AI 标注)模拟/实现
A positive integer in forest is the length of the stick at that position, and 0 means the position is empty. The nest is fixed at index bird, and forest[bird]=0. On the first trip, the bird searches right from the nest cell by cell for the nearest non-zero stick, takes it (that position becomes 0), and returns to the original nest. On the next trip it searches left from the nest for the nearest stick and returns to the nest again; after that it alternates right and left. It stops immediately once the total stick length reaches or exceeds 100. Return the original 0-based indices of all sticks taken, in collection order. Before the total reaches 100, the side needed in each round is guaranteed to still have a stick, so the search never goes out of bounds.
输入格式
The first line contains n and bird, and the second line contains n integers forest[i]. 3≤n≤1000, 0≤forest[i]≤50, 0≤bird<n, forest[bird]=0, sum(forest)≥100. Additional original guarantee: following the alternating process, while the total is below 100, the needed side always has a positive-length stick that has not been taken; an array whose total is large enough but that does not satisfy this per-round guarantee is not valid input. The numeric ranges come from Visa007, whose example and step-by-step process match exactly; Koddi002 itself explicitly guarantees a stick in every round, and Koddi did not preserve numeric bounds.
输出格式
One line of space-separated original 0-based indices, in exactly the actual collection order; do not output brackets or the element count.
样例 1
输入:
11 4
25 0 50 0 0 0 0 15 0 0 45
输出:
7 2 10
样例 2
输入:
3 1
50 0 50
输出:
2 0
样例 3
输入:
5 2
40 30 0 40 50
输出:
3 1 4
样例说明
Original Koddi Rules, Ranges from the Same Problem, and the Missing-Item Fix
In the fixed commit e66f809f4c953bce129f68491726176615db6afc, OA LIST/Koddi_OA/002_image.txt states explicitly that after taking each stick the bird returns to the original bird position, searches alternately starting from the right, and stops immediately once the total is at least 100; it also explicitly guarantees forest[bird]=0, a total length of at least 100, and that the needed side still has a stick in every round before the process ends. The old blocked reason, "behavior when sticks run out is unspecified", does not hold: the original guarantee rules out this case, so there is no need to invent out-of-bounds handling.
The example array in 002 is missing a 0: it has only 10 items yet outputs index 10. 003 itself repeats the complete 11-item array [25,0,50,0,0,0,0,15,0,0,45] and states step by step the lengths 15, 50, 45 at positions 7, 2, 10, with running totals 15, 65, 110, so Koddi003 alone uniquely corrects the missing item without guessing the input from another company. The original output [7,2,10] is unchanged.
The numeric constraints page for Koddi002/003 was not preserved. The ranges are explicitly taken from the same problem in OA LIST/Visa_OA/007_QQ_1741880100789.txt: 3≤n≤1000, 0≤forest[i]≤50, 0≤bird<n. The two are the same problem not just by title: Koddi002 and Visa004 match sentence by sentence in process and guarantees; Koddi003 and Visa005/006 match item by item in the complete 11-item input, bird=4, the output [7,2,10], and the 15/65/110 trace.
The Koddi summary page's example [50,0,0,40,0,30,0,20] with bird=1 is valid, and its output [3,0,5] is correct; the correction for the invalid example on the Visa summary page is not applied here. The input is n bird plus the array, and the output is the index sequence.