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. LINUX系统的常用知识

    常用的命令: man config   查看linux里面所有命令的详细描述 man pwd   按回车是一行一行的走,按空格是一页一页的走,按q键是退出的意思 mkdir test   创建文件夹p ...

  2. 使用SAXReader对XML进行操作

    该例子主要使用SAXReader对XML进行操作,browse.xml是Ango框架里面的XML文件 采用两种方法,第一种的全部是iterator,另外一种采用了部分的for each 代码如下 pr ...

  3. Diworth定理

    Diworth定理 一个序列中下降子序列的最少划分数个数等于最长上升子序列的长度. 一个序列中上升子序列的最少划分数个数等于最长下降子序列的长度. 每句中的前后两者互为偏序关系. 例题: Descri ...

  4. Linux 一款免费的shell工具 MobaXterm_Personal

    一款免费的shell工具 MobaXterm_Personal

  5. Codeforces Round #557 题解【更完了】

    Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...

  6. [WARNING] 找不到编译器:wepy-compiler-less。 [Error] 未发现相关 less 编译器配置,请检查wepy.config.js文件。

    npm install less 之后 npm install wepy-compiler-less 解决 请点赞!因为你的鼓励是我写作的最大动力! 吹逼交流群:711613774

  7. golang-笔记2

    结构体: 是一种数据 类型. type Person struct { —— 类型定义 (地位等价于 int byte bool string ....) 通常放在全局位置. name string ...

  8. eclipse 创建c/c++ 工程

    新建 注意选择如下选项,c和c++ 都一样的 然后,编译运行 参考: https://blog.csdn.net/u013610133/article/details/72857870 https:/ ...

  9. vue.js 中使用(...)运算符报错的解决方法

    vue.js 中使用(...)运算符报错的解决方法 Syntax Error:Unexpected token(XX:X) }, computed:{ ...mapGetters([ 'pageSiz ...

  10. Redis哨兵参数

    一.常用命令 sentinel的基本状态信息INFO 列出所有被监视的主服务器,以及这些主服务器的当前状态SENTINEL masters 列出指定主redis的从节点状态情况SENTINEL sla ...