zoukankan      html  css  js  c++  java
  • FJNU 1152 Fat Brother And Integer(胖哥与整数)

    FJNU 1152 Fat Brother And Integer(胖哥与整数)

    Time Limit: 1000MS   Memory Limit: 257792K

    【Description】

    【题目描述】

    Fat brother recently studied number theory, him came across a very big problem — minimum does not appear positive integer. Fat brother get n positive integers, he needs to find out the least a positive integer and the positive integer is not in his n positive integers.

    胖哥最近在学数论,他遇到了个重大问题— 最小未出现的正整数。胖哥有n个正整数,他需要找出不在这n个正整数中的最小正整数。

    【Input】

    【输入】

    There are multiple test cases. The first line of input contains an integer T (T <= 25) indicating the number of test cases. For each test case:

    The first line contains a single integer n (1 <= n <= 1000)

    The second line contains n positive integer ai ( 1 <= ai <= 1000000000)

    多组测试用例。

    第一行是一个整数T(T <= 25)表示测试用例的数量。对于每个测试用例:

    第一行是一个正整数n(1 <= n <= 1000)

    第二行有n个正整数 ai( 1 <= ai <= 1000000000)

    【Output】

    【输出】

    For each test case, output the minimum positive integer which didn’t appear in the n positive integer

    对于每个测试用例,输出不在这n个正整数里出现的最小正整数

    【Sample Input - 输入样例】

    【Sample Output - 输出样例】

    2

    5

    1 2 3 4 5

    5

    1 100 101 102 103

    6

    2

    【题解】

    最多就100个,直接暴力掉吧,注意下重复的元素就行了。

    【代码 C++】

     1 #include<cstdio>
     2 #include <algorithm>
     3 int main(){
     4     int t, n, i, data[1005];
     5     while (~scanf("%d", &t)){
     6         while (t--){
     7             for (i = scanf("%d", &n); i <= n; ++i) scanf("%d", &data[i]);
     8             std::sort(data, data + n + 1);
     9             for (i = data[0] = 0; i < n && data[i + 1] - data[i] < 2; ++i);
    10             printf("%d
    ", ++data[i]);
    11         }
    12     }
    13     return 0;
    14 }


     

  • 相关阅读:
    MySQL中默认值中用时间函数的问题
    mysql数据表的操作
    mysql数据库的基本操作
    mysql数据库的几个基本概念
    【转载】CentOS6.5_X64下安装配置MongoDB数据库
    Swap Swap,即交换分区
    linux中给PHP安装mongodb的扩展
    centos yum 安装 mongodb 以及php扩展
    设计模式主要分三个类型:创建型、结构型和行为型
    MySQL DELETE语句和TRUNCATE TABLE语句的区别
  • 原文地址:https://www.cnblogs.com/Simon-X/p/5414183.html
Copyright © 2011-2022 走看看