A15507 | Elimination of a Ring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Define a cyclic sequence of size $n$ as an array $s$ of length $n$ , in which $s_n$ is adjacent to $s_1$ .
Muxii has a ring represented by a cyclic sequence $a$ of size $n$ .
However, the ring itself hates equal adjacent elements. So if two adjacent elements in the sequence are equal at any time, one of them will be erased immediately. The sequence doesn't contain equal adjacent elements initially.
Muxii can perform the following operation until the sequence becomes empty:
- Choose an element in $a$ and erase it.
For example, if ring is $[1, 2, 4, 2, 3, 2]$ , and Muxii erases element $4$ , then ring would erase one of the elements equal to $2$ , and the ring will become $[1, 2, 3, 2]$ .
Muxii wants to find the maximum number of operations he could perform.
Note that in a ring of size $1$ , its only element isn't considered adjacent to itself (so it's not immediately erased).
Muxii has a ring represented by a cyclic sequence $a$ of size $n$ .
However, the ring itself hates equal adjacent elements. So if two adjacent elements in the sequence are equal at any time, one of them will be erased immediately. The sequence doesn't contain equal adjacent elements initially.
Muxii can perform the following operation until the sequence becomes empty:
- Choose an element in $a$ and erase it.
For example, if ring is $[1, 2, 4, 2, 3, 2]$ , and Muxii erases element $4$ , then ring would erase one of the elements equal to $2$ , and the ring will become $[1, 2, 3, 2]$ .
Muxii wants to find the maximum number of operations he could perform.
Note that in a ring of size $1$ , its only element isn't considered adjacent to itself (so it's not immediately erased).
输入格式
Each test contains multiple test cases. The first line contains a single integer $t$ ( $1\leq t\leq 100$ ) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer $n$ ( $1\leq n\leq 100$ ) — the size of the cyclic sequence.
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $1\leq a_i\leq n$ ) — the sequence itself.
It's guaranteed that $a_i\ne a_{i+1}$ for $1\leq i<n$ .
It's guaranteed that $a_n\ne a_1$ when $n>1$ .
The first line of each test case contains a single integer $n$ ( $1\leq n\leq 100$ ) — the size of the cyclic sequence.
The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $1\leq a_i\leq n$ ) — the sequence itself.
It's guaranteed that $a_i\ne a_{i+1}$ for $1\leq i<n$ .
It's guaranteed that $a_n\ne a_1$ when $n>1$ .
输出格式
For each test case, output a single integer — the maximum number of operations Muxii can perform.
输入输出样例
输入 #1
3 4 1 2 3 2 4 1 2 1 2 1 1
输出 #1
4 3 1
In the first test case, you can erase the second element first, then erase the remaining elements one by one in any order. In total, you can perform the operation $4$ times. Note that if you erase the first element first, then the sequence will be turned into $[2,3,2]$ and then immediately become $[2,3]$ .
In the second test case, you can erase the first element first, then the sequence becomes $[2,1]$ . Then you can erase all remaining elements one by one in any order.
In the second test case, you can erase the first element first, then the sequence becomes $[2,1]$ . Then you can erase all remaining elements one by one in any order.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted