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 (≤). 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

题意:

给你一个序列,让你找一个数x,x是不在这个序列里的最小正整数。

题解:

做此题的时候,最后一个测试点老是段错误,仔细查看下数据范围int,如果开一个int范围大小的数组判断,显然不可能,那么就猜下测试数据的范围。最后一个测试点没过由于开的数组没必要大于N。因为总共不会超过100000的数,所以在100002前一定会出现一个最小数没有出现。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n;
int a[];
int main(){
cin>>n;
for(int i=;i<=n;i++){
int x;
cin>>x;
if(x> && x<=){
//总共不会超过100000的数,所以在100002前一定会出现一个最小数没有出现
a[x]=;
}
}
for(int i=;i<=;i++){
if(!a[i]){
cout<<i;
break;
}
}
return ;
}

PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)的更多相关文章

  1. PAT 甲级 1144 The Missing Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343463260160 Given N integers, you ...

  2. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  3. PAT(A) 1144 The Missing Number(C)统计

    题目链接:1144 The Missing Number (20 point(s)) Description Given N integers, you are supposed to find th ...

  4. PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

  5. PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)

    1027 Colors in Mars (20 分)   People in Mars represent the colors in their computers in a similar way ...

  6. PAT 甲级 1054 The Dominant Color (20 分)(简单题)

    1054 The Dominant Color (20 分)   Behind the scenes in the computer's memory, color is always talked ...

  7. pat甲级 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  8. PAT Advanced 1019 General Palindromic Number (20 分)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  9. 1144. The Missing Number (20)

    Given N integers, you are supposed to find the smallest positive integer that is NOT in the given li ...

随机推荐

  1. PHP 判断终端是手机还是电脑访问网站代码

    用thinkphp做底层框架,判断客户是用pc访问还是手机访问的. <?php $platform = platform();//检测访问平台 //print_r($_SERVER);DIE; ...

  2. Redis面试基本问题

    Redis有哪些数据结构? 字符串String.字典Hash.列表List.集合Set.有序集合SortedSet.如果你是Redis中高级用户,还需要加上下面几种数据结构HyperLogLog.Ge ...

  3. sqlite3中给表添加列

    1.修改表名为临时表 ALTER TABLE {tableName} RENAME TO TempOldTable; 2.创建新表,跟原来的表名一致 CREATE TABLE {tableName} ...

  4. gdb, pdb笔记

    gdb gdb --args yourprogram 常用命令 r(run):从头开始运行 c(continue):继续运行 b(breakpoint) filepath:line or namesp ...

  5. input图片上传并显示查看判断图片类型

    有一个问题:上传一次在上传一次关闭按钮会出现两次,关闭之后还有一个(改好了可以告诉我我在修正过来) <div id="box"> <div class=" ...

  6. 2019/12/5BJFirstDay--scrum后台+cpp项目前台环境跑起来!!!

    1.配置服务器: 2.进入cd C:\java\25.beijing\06.vuejs\cpp201911221829\cpp 3.运行的命令是:npm run dev 4.先启动 5.然后再启动cp ...

  7. python-图像目标监测(1)识别答题卡

    # -*- coding: utf-8 -*- """ Created on Thu Dec 20 16:05:10 2018 @author: leizhen.liu ...

  8. 关于nginx反代jenkins报错 反向代理设置有误

    官方文档地址: https://wiki.jenkins.io/display/JENKINS/Running+Jenkins+behind+Nginx 直接解决的配置文件吧. 这是使用子域名,不使用 ...

  9. LoadRunner学习目录

    已更新: 未更新: 1.loadrunner 11破解版及破解包 2.如何录制一个LR脚本 3.自定义loadrunner脚本

  10. BAT 删除超过xx天的文件

    @echo offecho 删除n天前的备分文件和日志forfiles /p "C:\ShareF" /m *.zip /d -7 /c "cmd /c del @pat ...