• pat 1144 The Missing Number(20 分)


    1144 The Missing Number(20 分)

    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 (105​​). 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
    
     
     1 #include <map>
     2 #include <set>
     3 #include <queue>
     4 #include <cmath>
     5 #include <stack>
     6 #include <vector>
     7 #include <string>
     8 #include <cstdio>
     9 #include <cstring>
    10 #include <climits>
    11 #include <iostream>
    12 #include <algorithm>
    13 #define wzf ((1 + sqrt(5.0)) / 2.0)
    14 #define INF 0x3f3f3f3f
    15 #define LL long long
    16 using namespace std;
    17 
    18 const int MAXN = 1e6 + 10;
    19 
    20 int n, A[MAXN] = {0}, a;
    21 
    22 int main()
    23 {
    24     scanf("%d", &n);
    25     for (int i = 0; i < n; ++ i)
    26     {
    27         scanf("%d", &a);
    28         if (a <= 0 || a > MAXN) continue;
    29         A[a] = 1;
    30     }
    31     for (int i = 1; ; ++ i)
    32         if (A[i] == 0)
    33         {
    34             printf("%d
    ", i);
    35             break;
    36         }
    37     return 0;
    38 }
  • 相关阅读:
    题解 【洛谷】AT654
    题解【洛谷】CF134A
    jquery中select的应用
    Linq to xml 小例
    mongodb 使用场景和不使用场景
    一个面试题的解答-----从500(Id不连续)道试题库里随机抽取20道题!
    数据采集
    50款强力jquey,js 插件推荐
    node.js 学习
    wcf好文集合
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9579607.html
Copyright © 2020-2023  润新知