zoukankan      html  css  js  c++  java
  • hdu 5166(水题)

    Missing number

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1020    Accepted Submission(s): 518


    Problem 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
     
    Source
     
    题意:现在知道一个序列中缺了两个数,问缺的这两个数的最小值是多少?
    题解:标记已经有的数,扫一遍过去记录下最小的两个数而已.
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    using namespace std;
    bool Hash[1005];
    int main()
    {
        int tcase;
        scanf("%d",&tcase);
        while(tcase--)
        {
            int n;
            scanf("%d",&n);
            memset(Hash,0,sizeof(Hash));
            int MIN = 1005,MAX = 0;
            for(int i=1;i<=n;i++){
                int v;
                scanf("%d",&v);
                Hash[v] = true;
                MIN = min(v,MIN);
                MAX = max(v,MAX);
            }
            int cnt = 0;
            int res[5];
            for(int v=1;;v++){
                if(!Hash[v]){
                    res[cnt] = v;
                    cnt++;
                }
                if(cnt==2) break;
            }
            printf("%d %d
    ",res[0],res[1]);
        }
        return 0;
    }
  • 相关阅读:
    操作数据库pymysql
    深度学习-目标检测(Fast R-CNN)
    解释--全连接层输入大小固定
    深度学习-目标检测(IOU)
    深度学习-目标检测(SPPNet)
    深度学习-目标检测(R-CNN)
    机器学习-Whitening(白化)
    Win10 将slim加入PYTHONPYTH
    tensorboard 使用
    卷积神经网络--padding
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5681353.html
Copyright © 2011-2022 走看看