Source:

PAT A1144 The Missing Number (20 分)

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的更多相关文章

  1. Leetcode-268 Missing Number

    #268.  Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find ...

  2. Missing number

    Missing number 题目: Description There is a permutation without two numbers in it, and now you know wh ...

  3. 【LeetCode】268. Missing Number

    Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...

  4. hdu 5166 Missing number

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5166 Missing number Description There is a permutatio ...

  5. Missing Number, First Missing Positive

    268. Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find th ...

  6. HDU 5166 Missing number 简单数论

    Missing number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [ ...

  7. 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 ...

  8. PAT 1144 The Missing Number

    1144 The Missing Number (20 分)   Given N integers, you are supposed to find the smallest positive in ...

  9. [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 ...

随机推荐

  1. Spring Data Jpa-动态查询条件

    /** * * 查看日志列表-按照时间倒序排列 * * @author: wyc * @createTime: 2017年4月20日 下午4:24:43 * @history: * @return L ...

  2. ZooKeeper的应用场景(转)

    应用场景1 :统一命名服务 分布式应用中,通常需要一套完备的命令机制,既能产生唯一的标识,又方便人识别和记忆. 我们知道,每个ZNode都可以由其路径唯一标识,路径本身也比较简洁直观,另外ZNode上 ...

  3. php svn仓库提交预处理

    需要做的事情 1.检查是否填写注释2.php文件是否有语法错误 pre-commit脚本 hook脚本名称:hooks/pre-commit REPOS="$1" TXN=&quo ...

  4. MySQL系列:innodb源码分析 图 ---zerok的专栏

    http://blog.csdn.net/yuanrxdu/article/details/40985363

  5. 让devstack中的vm訪问外网

    devstack默认会建立一个Public网络,地址为172.24.4.0/24,可是这个网络并非运营商分配给我们的网络.所以仅仅能通过nat的方式让devstack建立的虚拟机訪问外网. br-ex ...

  6. Cookie &amp;&amp; Session &amp;&amp; Token

    Cookies Cookie的由来: HTTP 本身是一个无状态的 request/response 协议. server接收一个来自client的request, 处理完以后返回一个response ...

  7. Sqlite3插入大量数据性能优化

    近期做的一个项目数据量很大.文本数据有30多M.这样就遇到一个问题.插入数据库时很慢. 这里记录下,优化方法很easy. 原文地址:http://blog.csdn.net/qqmcy/article ...

  8. 对扩展openflow协议的一点思考

         软件定义X变得越来越火,正所谓,Software is eating the world. 软件定义网络也是如此.不论是在工业界还是学术界都将是一次伟大的革命,都在紧随着这个行业的方向,找自 ...

  9. Java-JRE:JRE百科

    ylbtech-Java-JRE:JRE百科 JRE是Java Runtime Environment缩写,指Java运行环境,是Sun的产品.运行JAVA程序所必须的环境的集合,包含JVM标准实现及 ...

  10. leetcode排列组合相关

    目录 78/90子集 39/40组合总和 77组合 46/47全排序,同颜色球不相邻的排序方法 78/90子集 输入: [1,2,2] 78输出: [[], [1], [2], [1 2], [2], ...