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 }
  • 相关阅读:
    Postman post csrf_token
    CBV
    nginx+uWSGI+django部署web服务器
    JS绘图
    get_字段_display()
    limit_choices_to
    window.onload=function(){};
    模拟百度搜索项目
    事件冒泡
    解绑事件
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9579607.html
Copyright © 2011-2022 走看看