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. HTMLParser in python

    You can know form the name that the HTMLParser is something used to parse HTML files.  In python, th ...

  2. HDU 4891 The Great Pan (字符串处理)

    题目链接:HDU 4891 The Great Pan 求一串字符有多少种不同的意思,当中关心'{','}'之间的'|'. 和'$','$'之间的空格,连续N个空格算N+1种. AC代码: #incl ...

  3. HDU 4598

    这道题其实不需要考虑具体数值,但可以肯定的是,相连边的两端点必定有一正一负,至于谁正谁负,并不重要,这是可以思考的,很明显的一个二分图性质,如果不满足此条件,是不可能满足题目第二个条件的.所以首先对题 ...

  4. [Node.js] Add Logging to a Node.js Application using Winston

    Winston is a popular logging library for NodeJS which allows you to customise the output, as well as ...

  5. ASP.NET—016:ASP.NET中保存文件对话框

    本想在asp.net中使用savediallog保存文件,结果提示:当应用程序不是以 UserInteractive 模式执行时显示模式对话框或窗口是无效操作. 在ASP.NET中使用例如以下方式.保 ...

  6. 初入股市之 Hello Stock

    牛市的诱惑 12月3日的深沪股市,再次创出单日成交量的历史记录.这些天.各地证券部里挤满了新开户的股民.这些菜鸟们带着虔诚.希望和身家性命,挤进了一片前途未卜的莽原.当中就包含我.事实上一直有想去尝试 ...

  7. hdu 5094 Maze bfs

    传送门:上海邀请赛E 给定一个n×m的迷宫,给出相邻格子之间的墙或者门的信息,墙说明不可走,假设是门则须要有相应的钥匙才干通过,问是否可以从(1,1)到达(n,m) 一个带状态的bfs,再另记一个状态 ...

  8. 利用jquery将页面中所有目标为“#‘的链接改为其他URL

    有一张页面草稿,开始时为了方便,里面差不多所有的<a>都指向了"#".现在要修改为另一个地址,难道要全部修改吗?用jquery 改改就好.代码如下: <scrip ...

  9. Delphi7中单元文件内各个部分的执行顺序

    注:本文主要是讨论delphi程序启动时和退出时的执行顺序,期间有些知识来源于Delphi帮助,有些来自<Delphi7程序设计教程>(这本书只告诉我有initialization 和 f ...

  10. .Net-ASP.NET Web API:目录

    ylbtech-.Net-ASP.NET Web API:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https://www.asp.net/we ...