CF->CodeForces 137B
2013-10-12 18:56
471 查看
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces
137B
Description
"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 a1, a2, ..., an 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).
Input
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 ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).
Output
Print the only number — the minimum number of changes needed to get the permutation.
Sample Input
Input
Output
Input
Output
Input
Output
Hint
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.
Submit Status Practice CodeForces
137B
Description
"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 a1, a2, ..., an 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).
Input
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 ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).
Output
Print the only number — the minimum number of changes needed to get the permutation.
Sample Input
Input
3 3 1 2
Output
0
Input
2 2 2
Output
1
Input
5
5 3 3 3 1
Output
2
Hint
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.
#include <iostream> using namespace std; int array[5001]; int main() { int t, x; cin >> t; for (int i = 0; i < t; i++) { cin >> x; array[x] = 1; } int num = 0; for (int i = 1; i <= t; i++) { if (!array[i]) { num++; } } cout << num << endl; return 0; }
相关文章推荐
- CF->CodeForces 137C
- CF->CodeForces 256A
- CF->CodeForces 137A
- coldfusion <cfmail>
- <cf>Dubstep
- <cf>System of Equations(水题)
- <cf>Two Problems
- Codeforces 61E Enemy is weak 求i<j<k && a[i]>a[j]>a[k] 的对数 树状数组
- <cf>Sysadmin Bob
- CF 346 B vector<pair> s[100]
- <cf>Schedule
- ACM->CF
- ACM->CF 358A
- <cf>Walking in the Rain
- <cf> A. Cloning Toys
- Codeforces 61E Enemy is weak 乞讨i<j<k && a[i]>a[j]>a[k] 对数的 树阵
- <cf> Funky Numbers
- 关于 codeforces中的 int abs(int x) 还有头文件 # include <algorithm> 不带.h
- <cf>Hexadecimal's theorem
- <cf>Square