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;
    }
  • 相关阅读:
    Java 传递参数时,传递一个变量快还是传递一个实体类?
    13 设计模式
    12 反射
    11.多线程&&并发
    10.输入输出
    9.异常Exception
    7.正则表达式
    5.数组
    6.常见对象
    上传本地项目到Github
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4796215.html
Copyright © 2011-2022 走看看