CF2153A.Circle of Apple Trees
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n apple trees arranged in a circle. Each tree bears exactly one apple, and the beauty of the apple on the i-th tree is given by bi for all 1≤i≤n. You start in front of tree 1.
At each tree, you may choose to either eat the apple or skip it. After making your choice, you move to the next tree: from tree i, you move to tree i+1 for 1≤i≤n−1, and from tree n, you move back to tree 1. This process continues indefinitely as you move through the trees in a cycle.
However, you have a special condition: you may only eat an apple if its beauty is strictly greater than the beauty of the last apple you ate. For example, if b=[2,1,2,3] and you eat the apple on tree 1 (beauty 2), you cannot eat the apples on trees 2 and 3 because their beauties are not greater than 2. However, you may eat the apple on tree 4 since b4=3>2.
Note that you are allowed to skip an apple when you first encounter it, and you can choose to eat it later on a subsequent cycle.
Your task is to determine the maximum number of apples you can eat if you make optimal decisions on when to eat or skip each apple.
有 n 棵苹果树围成一个圆圈。每棵树上恰好结一个苹果,第 i 棵树上的苹果的美丽值为 bi(其中 1≤i≤n)。你从第 1 棵树前开始。
在每一棵树处,你可以选择吃掉该苹果,或跳过它。做出选择后,你将移动到下一棵树:从第 i 棵树出发,当 1≤i≤n−1 时,你移动到第 i+1 棵树;而从第 n 棵树出发时,你回到第 1 棵树。这一过程无限持续,你将不断绕圈经过这些树。
但你有一个特殊限制:仅当当前苹果的美丽值严格大于你上一次吃掉的苹果的美丽值时,你才可以吃掉它。
例如,若 b=[2,1,2,3],且你吃了第 1 棵树上的苹果(美丽值为 2),那么你无法吃第 2 棵和第 3 棵树上的苹果,因为它们的美丽值均不大于 2;但你可以吃第 4 棵树上的苹果,因为 b4=3>2。
注意:你可以在第一次经过某棵苹果树时跳过该苹果,并在后续某一轮循环中再选择吃掉它。
你的任务是:在对每个苹果的吃与跳过作出最优决策的前提下,求出你能吃到的苹果数量的最大值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤100) — the number of apple trees.
The second line of each test case contains n integers b1,b2,…,bn (1≤bi≤n) — the beauty of the apples on the trees.
Note that there are no constraints on the sum of n over all test cases.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 苹果树的数量。
每个测试用例的第二行包含 n 个整数 b1,b2,…,bn(1≤bi≤n)—— 各棵树上苹果的美丽值。
注意:对所有测试用例的 n 之和不作任何限制。
输出格式
For each test case, output a single integer representing the maximum number of apples you can eat.
对于每个测试用例,输出一个整数,表示你能吃到的苹果的最大数量。
输入输出样例
输入#1
3 4 2 2 2 2 5 1 4 5 1 2 6 5 4 2 1 2 3
输出#1
1 4 5
说明/提示
In the first test case, since all apples have the same beauty, no matter which apple you eat first, you cannot eat any others afterward. Hence, the maximum number of apples that you can eat is 1.
In the second test case, you can eat four apples as follows:
- At tree 1, skip the apple.
- At tree 2, skip the apple.
- At tree 3, skip the apple.
- At tree 4, eat the apple (beauty 1).
- At tree 5, eat the apple (beauty 2).
- At tree 1, skip the apple. You are not allowed to eat the apple as its beauty (b1=1) is not greater than the beauty of the last apple you ate (b5=2).
- At tree 2, eat the apple (beauty 4).
- At tree 3, eat the apple (beauty 5).
It can be proven that it is not possible to eat all five apples; hence, the maximum number of apples that you can eat is 4.
在第一个测试用例中,由于所有苹果的美丽值均相同,无论你先吃哪一个苹果,之后都无法再吃其他苹果。因此,你能吃的苹果的最大数量为 1。
在第二个测试用例中,你可以按如下方式吃掉四个苹果:
- 在第 1 棵树处,跳过该苹果。
- 在第 2 棵树处,跳过该苹果。
- 在第 3 棵树处,跳过该苹果。
- 在第 4 棵树处,吃掉该苹果(美丽值为 1)。
- 在第 5 棵树处,吃掉该苹果(美丽值为 2)。
- 在第 1 棵树处,跳过该苹果。你不能吃它,因为它的美丽值(b1=1)不大于你上一次所吃苹果的美丽值(b5=2)。
- 在第 2 棵树处,吃掉该苹果(美丽值为 4)。
- 在第 3 棵树处,吃掉该苹果(美丽值为 5)。
可以证明,不可能吃掉全部五个苹果;因此,你能吃的苹果的最大数量为 4。
输入解题思路,AI测评打分。不知道怎么写?