A8291 | Permutation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.
You are given an arbitrary sequence $a_{1},a_{2},...,a_{n}$ containing $n$ integers. Each integer is not less than $1$ and not greater than $5000$ . Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
The sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.
You are given an arbitrary sequence $a_{1},a_{2},...,a_{n}$ containing $n$ integers. Each integer is not less than $1$ and not greater than $5000$ . Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
输入格式
The first line of the input data contains an integer $n$ ( $1<=n<=5000$ ) which represents how many numbers are in the sequence. The second line contains a sequence of integers $a_{i}$ ( $1<=a_{i}<=5000,1<=i<=n$ ).
输出格式
Print the only number — the minimum number of changes needed to get the permutation.
输入输出样例
输入 #1
3 3 1 2
输出 #1
0
输入 #2
2 2 2
输出 #2
1
输入 #3
5 5 3 3 3 1
输出 #3
2
The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with number 2.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted