CodeForce 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
3
3 1 2
0
2
2 2
1
5
5 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.
这道题的题意是给出一个数n,再给出n个数,要求从1到n都要出现在这个数组中,可以改变任意一个数以达到这个状态,问最小需要几次。这个题需要注意的地方有,数组给的可能是乱序的 ,数组中可能有大于n的数,应该作为非法的数处理。
#include<iostream>
using namespace std;
#include<algorithm>
int a[];
int main()
{
int num = ,i,j = ;
cin >> num;
for(i = ;i < num;i++)
{
cin >> a[i];
}
sort(a,a+num);//将数组排序便于统计
for(i = ;i < num && a[i] <= num;i++)//统计小于num且不同的数
{
if(a[i] == a[i+])continue;
else j++;
}
cout << num - j;
return ;
}
CodeForce 137B的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- CF516D Drazil and Morning Exercise
cf luogu 首先每个点到最远点的距离可以预处理出来,这个距离显然是这个点到树直径两端点的最大值.把那个距离记为\(d_i\),然后从小到大枚举\(d_i\),并强制它为最大的\(d_i\),那么 ...
- python爬虫下正则各种字符串数据匹配
s = '*\/:?"<>|' #这9个字符在Windows系统下是不可以出现在文件名中的str1 = '\巴拉<1"!11[]>1*hgn/p:?|' # ...
- js大神成长指路
随着我的成长,我的兴趣也在不断地分化,他们似乎都是不相关的领域.我喜欢数学就像我喜欢历史一样.我的目标是成为一个多才多艺的人——一个学者——在许多领域都能成为杰出的人才.这是一项艰巨的任务.突然间,我 ...
- ubuntu install opencv
1. install the newest opencv version pip install opencv-python
- 第六章·Logstash深入-收集java日志
1.通过Logstash收集java日志并输出到ES中 因为我们现在需要用Logstash收集tomcat日志,所以我们暂时将tomcat安装到Logstash所在机器,也就是db03:10.0.0. ...
- deep_learning_CNN
AI学习笔记——卷积神经网络(CNN) image.png 上篇文章简单地地介绍了神经网络和深度学习,在神经网络中,每一层的每个神经元都与下一层的每个神经元相连(如下图), 这种连接关系叫全连接(Fu ...
- 十二,k8s集群访问控制之RBAC授权
目录 角色访问控制RBAC (Role-Based Access Control) 常用的授权插件: RBAC控制: role 和 clusterrole rolebinding 和 clusterr ...
- ELK展示NGINX访问IP地理位置图
一.设置NGINX日志格式 [root@zabbix_server ~]# vim /etc/nginx/nginx.conf log_format access_json_log '{"@ ...
- solr 查询解析器
定义 查询解析器用于将查询语句(q参数)解析成搜索语法. 默认解析器:lucene Solr在查询的时候,用到了QueryParser对用户输入做解析,solr默认使用的解析器是lucene,被称之为 ...
- spring cache会默认使用redis作为缓存吗?
web项目中,只需要配置 redis 的IP,端口,用户名和密码就可以使用redis作为缓存了,不需要在在java 代码中配置redisConfig,redisConfig只是作为缓存配置的辅助,比如 ...