PAT_A1144#The Missing Number
Source:
Description:
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.
Output Specification:
Print in a line the smallest positive integer that is missing from the input list.
Sample Input:
10
5 -25 9 6 1 3 4 2 5 17
Sample Output:
7
Keys:
- 散列(Hash)
Code:
/*
Data: 2019-05-23 19:50:36
Problem: PAT_A1144#The Missing Number
AC: 05:24 题目大意:
给定N(<=1e5)个整数(int范围内),找出不在表中的最小正数;
*/ #include<cstdio>
#include<map> int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,x;
std::map<int,int> mp;
scanf("%d", &n);
for(int i=; i<n; i++)
{
scanf("%d", &x);
mp[x]=;
}
for(int i=; i<1e9; i++)
{
if(mp[i]==)
{
printf("%d\n", i);
break;
}
} return ;
}
PAT_A1144#The Missing Number的更多相关文章
- Leetcode-268 Missing Number
#268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...
- Missing number
Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...
- 【LeetCode】268. Missing Number
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...
- hdu 5166 Missing number
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5166 Missing number Description There is a permutatio ...
- Missing Number, First Missing Positive
268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find th ...
- HDU 5166 Missing number 简单数论
Missing number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) [ ...
- Missing number in array
Given an array of size n-1 and given that there are numbers from 1 to n with one missing, the missin ...
- PAT 1144 The Missing Number
1144 The Missing Number (20 分) Given N integers, you are supposed to find the smallest positive in ...
- [LintCode] Find the Missing Number 寻找丢失的数字
Given an array contains N numbers of 0 .. N, find which number doesn't exist in the array. Example G ...
随机推荐
- N天学习一个linux命令之ps
ps命令 用途 显示系统进程信息 用法 ps [options] 常用选项 选项有三种风格,这里是指Unix风格 (Unix,BSD,GNU LONG OPTIONS) 简单刷选类 -A, -e 显示 ...
- 【Todo】Java TreeSet学习 & ceiling,floor
参考 http://www.yiibai.com/java/util/java_util_treeset.html 另,用Java的TreeSet的ceiling可以模拟upper_bound(获得更 ...
- CF #330 D2 E
相当于给你一些点,要你最多删除不超过k,使得能使用一个边长为整数的长方形,与XY轴平行,使长方形的面积最小. 上课时拿笔来画画,然后忽然思路就开了,要是比赛也这样就好了~~先按X,Y分别排序,由于K较 ...
- HDU 4362
方程很简单 p[i][j] = min{dp[i-1][k] + |pos[i-1][k] - pos[i][k]|} + v[i][j]; 循环求值肯定TLE,主要是绝对值不方便.好吧,我真的BI了 ...
- 用Radeon RAMDisk在Windows 10中创建关机或重新启动不消失的内存虚拟盘
之前用ImDisk创建的内存虚拟盘每次关机或重新启动后就会消失,想要开机自己主动创建内存虚拟盘尽管能够用批处理来实现,但还是有点不爽.下载试用了Radeon RAMDisk(Radeon_RAMDis ...
- [字典树] poj 2418 Hardwood Species
题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS Memory ...
- 【POJ 2983】Is the Information Reliable?(差分约束系统)
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...
- Android - Error: "java.io.IOException: setDataSource failed.: status=0x80000000"
Error: "java.io.IOException: setDataSource failed.: status=0x80000000" 本文地址: http://blog.c ...
- Ubuntu Linux 安装 .7z 解压和压缩文件
安装方法: sudo apt-get install p7zip 解压文件: 7z x manager.7z -r -o /home/xx解释如下:x 代表解压缩文件,并且是按原始目录解压(还有个参数 ...
- git fetch批处理,遍历一个文件夹下的所有子目录,执行git fetch --all
echo off for /d %%i in (*) do ( echo %%i cd %%i git fetch --all cd .. ) 判断子目录是否有.git文件夹 echo off for ...