zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    模板方法模式
    LINQ多条件OR模糊查询
    在LINQ中实现多条件联合主键LEFT JOIN
    js只显示整点
    Vue-cli2中处理跨域
    vue动态绑定类(实现tab)
    Vue中引入cdn同时防止cdn挂掉
    vue+nginx开启gzip压缩
    Vue路由守卫
    vue-router嵌套路由和二级目录(域名)
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9579607.html
Copyright © 2011-2022 走看看