CF137B.Permutation
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
"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).
“嘿,该做作业了!”——波利卡普斯心想,当然,他从自己最喜爱的科目——信息技术课开始做起。波利卡普斯在 20 分钟内成功解决了所有题目,但最后一题除外。然而,在花费了相当长的时间后仍未能解出最后一题,这位少年便请你来帮忙。
若一个包含 $ n $ 个整数的序列恰好包含从 $ 1 $ 到 $ n $ 的所有整数各一次,则称该序列为一个排列(permutation)。
现给定一个任意的整数序列 $ a_1,,a_2,,\dots,,a_n $,其中共含 $ n $ 个整数,且每个整数均不小于 $ 1 $、不大于 $ 5000 $。请确定:波利卡普斯至少需要修改多少个元素,才能将该序列变为一个排列(他既不能删除也不能添加数字)。每次修改操作仅允许将序列中的某一个元素替换为另一个整数。
输入格式
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).
输入数据的第一行包含一个整数 n(1≤n≤5000),表示序列中数字的个数。第二行包含一个整数序列 ai(1≤ai≤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.
第一个样例中已包含一个排列,因此无需进行任何替换。
第二个样例中,只需将第一个元素替换为数字 1,即可使该序列成为所需的排列。
第三个样例中,我们可以将第二个元素替换为数字 4,同时将第四个元素替换为数字 2。
输入解题思路,AI测评打分。不知道怎么写?