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 (≤10​5​​). 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

#include <stdio.h>
#include <algorithm>
#include <limits.h>
#include <set>
using namespace std;
int main() {
int n;
scanf("%d", &n);
set<int> st;
for (int i = ; i < n; i++) {
int tmp;
scanf("%d", &tmp);
if (tmp > ) {
st.insert(tmp);
}
}
int j = ;
for (auto it = st.begin(); it != st.end(); it++) {
if (*it > j) {
printf("%d", j);
break;
}
else j++;
}
if(j==st.size()+)printf("%d",j);
}

注意点:这里只保证了输入数不超过int大小,用hash不好做,不如直接用set,自动升序排列,找到第一个不满足的数。

第二个坑是测试点2-5都是输入数据连续的,缺失的是输入数据后面那个数

PAT A1144 The Missing Number (20 分)——set的更多相关文章

  1. PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)

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

  2. PAT A1019 General Palindromic Number (20 分)

    AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...

  3. PAT 1144 The Missing Number

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

  4. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  5. PAT乙级:1088 三人行 (20分)

    PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...

  6. PAT乙级:1064 朋友数 (20分)

    PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...

  7. [PAT] 1144 The Missing Number(20 分)

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

  8. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  9. PAT 1144 The Missing Number[简单]

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

随机推荐

  1. JAVA的高并发基础认知 二

    一.JAVA高级并发 1.5JDK之后引入高级并发特性,大多数的特性在java.util.concurrent 包中,是专门用于多线程发编程的,充分利用了现代多处理器和多核心系统的功能以编写大规模并发 ...

  2. √n求单值欧拉函数

    基本定理: 首先看一下核心代码: 核心代码 原理解析: 当初我看不懂这段代码,主要有这么几个问题: 1.定理里面不是一开始写了一个n*xxx么?为什么代码里没有*n? 2.ans不是*(prime[i ...

  3. GIS小知识

    1.GeoJson 2.EPSG:3857 几何对象:{"id":0,"style":null,"parts":[1],"poin ...

  4. 【读书笔记】iOS-自定义URL Scheme注意事项

    如果两个不同的应用注册了同样的URL Scheme,那么后安装的应用会响应符合这种协议格式的URL. 如果你的应用的iPhone和iPad版是各自独立的(即不是Universal类型的),那么你就不应 ...

  5. [20171218]varchar2(4000)如何保存.txt

    [20171218]varchar2(4000)如何保存.txt --//以前写的,不知道为什么被删除了,现在补上. 如果一行能被存储于一个数据块(data block)中,那么其行头(row hea ...

  6. Cannot find wrapper assembly for type library "ADODB". in VS2017

    Delete Microsoft ActiveX Data Objects {version} Library and then add it back. After resolving the pr ...

  7. 将mssql数据库高版本迁移到低版本

    将mssql数据库高版本迁移到低版本 在低版本目标数据库中创建目标空数据库[TargetDb] ,注意新建数据库即可,不要创建任何表 在低版本数据库中,选中[服务器对象=>链接服务器] 右键[新 ...

  8. 图解get方法与filter方法

    在django的数据库查找方法中,get与filter方法是查找单目数据,用图记录了这两个方法查找数据各自返回的是什么?

  9. chrony时间服务器

    chrony有着比ntp服务器更好的优势来同步服务,在集群架构中,采用此种服务来同步时间也是最好的方式. 在集群环境中,一般都是一个服务器,然后上百个客户端来同步服务端的时间,接下来我们看看如何配置. ...

  10. January 23rd, 2018 Week 04th Tuesday

    Remembrance is a form of meeting, forgetfulness is a form of freedom. 记忆是一种相遇,遗忘是一种自由. Cherish those ...