HBC232080Dong Zhi,语言题Constructive Problem题解

云中君 算法基础篇 28 0
题库丰富多样,涵盖各个领域,全网最全C++题库,让您在练习中不断成长!
Adam has an array aaaconsisting of nnn integers a0,a1,...,an1a_0, a_1, ..., a_{n-1}a0,a1,...,an1. We call this array beautiful if the number of occurrences of iii is aia_iai for i∈[0,n1]iin [0,n-1]i∈[0,n1]. For example: [1,2,1,0][1,2,1,0][1,2,1,0]is beautiful. In this array, 000 appears 111 time, 111 appears 222 times, 222 appears 111 time, and 333 appears 000 times, and a0=1,a1=2,a2=1,a3=0a_0=1,a_1=2,a_2=1,a_3=0a0=1,a1=2,a2=1,a3=0. [0,1][0,1][0,1]is not beautiful. Because a0=0a_0=0a0=0but in fact 000 appears 111 time. Find a beautiful array of length nnn. If there are multiple answers, output any. If there is no beautiful array of length nnn, output 1-11.

Adam has an array aaa consisting of nnn integers a0,a1,...,an−1a_0, a_1, ..., a_{n-1}a0​,a1​,...,an−1​. We call this array beautiful if the number of occurrences of iii is aia_iai​ for i∈[0,n−1]iin [0,n-1]i∈[0,n−1]. For example: [1,2,1,0][1,2,1,0][1,2,1,0] is beautiful. In this array, 000 appears 111 time, 111 appears 222 times, 222 appears 111 time, and 333 appears 000 times, and a0=1,a1=2,a2=1,a3=0a_0=1,a_1=2,a_2=1,a_3=0a0​=1,a1​=2,a2​=1,a3​=0. [0,1][0,1][0,1] is not beautiful. Because a0=0a_0=0a0​=0 but in fact 000 appears 111 time. Find a beautiful array of length nnn. If there are multiple answers, output any. If there is no beautiful array of length nnn, output −1-1−1.

HBC232080Dong Zhi,语言题Constructive Problem题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
成为编程大师,不再是梦想!全网最全C++题库,助您开启编程新篇章。

标签: HBC232080Dong Zhi 语言题Constructive Problem题解