CF->CodeForces 137B
来源:互联网 发布:js 数组去掉最后一个 编辑:程序博客网 时间:2024/05/02 03:05
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
33 1 2
0
22 2
1
55 3 3 3 1
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 137B
- CF 333 B.Chips CodeForces【伪容斥】
- CF->CodeForces 137A
- CF->CodeForces 137C
- CF Codeforces Round #258 (Div. 2) B (451B)
- 【Floyd】【CF】CodeForces 301B Yaroslav and Time
- CF-Codeforces Round #392 (Div. 2)-B-Blown Garland
- cf Educational Codeforces Round 27 B. Luba And The Ticket
- cf CodeForces
- cf-B
- cf B
- CodeForces-137B Permutation
- Codeforces-137B-Permutation
- 【打CF,学算法——二星级】CodeForces 96B Lucky Numbers (构造/dfs)
- 【打CF,学算法——三星级】CodeForces 615B Longtail Hedgehog (DFS/拓扑排序)
- 【打CF,学算法——一星级】CodeForces 227B Effective Approach (水题)
- 【打CF,学算法——二星级】CodeForces 417B Crash (水题)
- 【打CF,学算法——二星级】Codeforces 22B Bargaining Table(区域和)
- word2003中自动编号的使用和取消
- CF->CodeForces 137A
- Qt核心剖析:moc
- Global.asax 文件是什么
- 关于一道简单的智力题
- CF->CodeForces 137B
- C++快速学习之旅——C++和java的编译区别
- hdu 4055 2011 Asia Dalian Regional Contest
- CF->CodeForces 137C
- cocos2dx搭建android环境记录
- java泛型详解
- 黑马程序员_<<享元模式>>
- fatal error C1859 意外的预编译头错误,只需重新运行编译器
- CF->CodeForces 256A