zoukankan      html  css  js  c++  java
  • hdu 5166 Missing number

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=5166  

    Missing number

    Description

    There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.

    Input

    There is a number T shows there are T test cases below. (T10)
    For each test case , the first line contains a integers n , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.(1n1,000)

    Output

    For each case output two numbers , small number first.

    Sample Input

    2
    3
    3 4 5
    1
    1

    Sample Output

    1 2
    2 3

    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<map>
    using std::map;
    using std::min;
    using std::find;
    using std::pair;
    using std::vector;
    using std::multimap;
    #define pb(e) push_back(e)
    #define sz(c) (int)(c).size()
    #define mp(a, b) make_pair(a, b)
    #define all(c) (c).begin(), (c).end()
    #define iter(c) __typeof((c).begin())
    #define cls(arr, val) memset(arr, val, sizeof(arr))
    #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    #define rep(i, n) for(int i = 0; i < (int)n; i++)
    #define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)
    const int N = 1010;
    const int INF = 0x3f3f3f3f;
    bool vis[N];
    void solve(int n) {
        int v;
        vector<int> ans;
        cls(vis, false);
        rep(i, n) {
            scanf("%d", &v);
            vis[v] = true;
        }
        rep(i, n + 2) {
            if(!vis[i + 1]) ans.pb(i + 1);
        }
        printf("%d %d
    ", ans[0], ans[1]);
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w+", stdout);
    #endif
        int t, n;
        scanf("%d", &t);
        while(t--) {
            scanf("%d", &n);
            solve(n);
        }
        return 0;
    }
  • 相关阅读:
    关联容器:unordered_map详细介绍
    c++类成员变量初始化相关问题
    全方位深入理解JavaScript面向对象
    彻底搞懂 JS 中 this 机制
    IDEA 服务器热部署详解(On Update action/On frame deactivation)
    Java书籍推荐
    JSTL
    谭浩强的书中的一些知识点(1)
    EL表达式
    第一章第二章
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4796215.html
Copyright © 2011-2022 走看看