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. 关于Spring的常用注解和接口

    接口 1. BeanPostProcessor 2. FactoryBean 3. Condition 4. ImportSelector 5. ImportBeanDefinitionRegitra ...

  2. maven项目重构-使用了mybatis generator插件

    1.在worksapce下,dos窗口输入spring init -g=com.briup.apps -a=poll3 -d=mysql,mybatis,web poll3 2.下载依赖,cd到pol ...

  3. 关于跨域介绍和djiago解决跨域问题

    什么是跨域? 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全限制. 什么是同源策略? 同源策略又分为以下两种 DOM同源策略:禁止对不 ...

  4. go协程的特点

    go奉行通过通信来共享内存,不像c和c++通过共享内存来通信 协程是轻量级的线程,编译器做优化** 有独立的栈空间 共享程序堆空间 调度由用户控制 协程是轻量级的线程 并行:多个cpu共同执行 并发 ...

  5. ES 调优查询亿级数据毫秒级返回!怎么做到的?--文件系统缓存

    一道面试题的引入: 如果面试的时候碰到这样一个面试题:ElasticSearch(以下简称ES) 在数据量很大的情况下(数十亿级别)如何提高查询效率? 这个问题说白了,就是看你有没有实际用过 ES,因 ...

  6. 【转载】Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration info

    网上查到http://social.msdn.microsoft.com/Forums/vstudio/en-US/58271e39-beca-49ac-90f9-e116fa3dd3c0/mxed- ...

  7. nohup 后台执行

    nohup  默认是当前用户执行的,当当前用户退出会导致执行进程异常. 所以正确的 nohup 是指定 /bin/bash 进行执行. nohup /bin/bash/ /opt/script/s.s ...

  8. 【概率论】5-6:正态分布(The Normal Distributions Part III)

    title: [概率论]5-6:正态分布(The Normal Distributions Part III) categories: - Mathematic - Probability keywo ...

  9. CF1208题解

    C \(\begin{aligned}\ 0 0 1 1\\ 0 0 1 1\\ 2 2 3 3\\ 2 2 3 3\\ \end{aligned}\)将每个四方格分别加上\(0,4,8,12\) D ...

  10. SpringMVC从Request域中获取数据

    SpringMVC从Request域中获取数据的三种方式 SpringMVC环境自行搭建, 约定存在如下目录和文件:/WEB-INF/pages/success.jsp 方式一:传入Model对象 前 ...