欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2153A.Circle of Apple Trees
Circle of Apple Trees
There are apple trees arranged in a circle. Each tree bears exactly one apple, and the beauty of the apple on the -th tree is given by for all . You start in front of tree .
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 , you move to tree for , and from tree , you move back to tree . 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 and you eat the apple on tree (beauty ), you cannot eat the apples on trees and because their beauties are not greater than . However, you may eat the apple on tree since .
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.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the number of apple trees.
The second line of each test case contains integers () — the beauty of the apples on the trees.
Note that there are no constraints on the sum of over all test cases.
Output
For each test case, output a single integer representing the maximum number of apples you can eat.
Note
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 .
In the second test case, you can eat four apples as follows:
- At tree , skip the apple.
- At tree , skip the apple.
- At tree , skip the apple.
- At tree , eat the apple (beauty ).
- At tree , eat the apple (beauty ).
- At tree , skip the apple. You are not allowed to eat the apple as its beauty () is not greater than the beauty of the last apple you ate ().
- At tree , eat the apple (beauty ).
- At tree , eat the apple (beauty ).
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 .
Samples
3
4
2 2 2 2
5
1 4 5 1 2
6
5 4 2 1 2 3
1
4
5
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |