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 物理机虚拟化

    前言 我有一台安装了 RHCA 资源的磁盘,然而每次开机时需要切换启动项为该磁盘.于是我想将它实现物理虚拟化. 工具 Windows 10 RHCA Disk Virtualbox 5.1 Virtu ...

  2. webpack打包绝对路径引用资源和element ui字体图标不显示的解决办法

    webpack打包绝对路径引用资源解决办法: 打开webpack.prod.conf.js 找到output:增加 publicPath: './',  即可,如图  element ui字体图标不显 ...

  3. Kubernetes 学习26 基于kubernetes的Paas概述

    一.概述 1.通过以往的学习应该可以了解到k8s 和以往提到的devops概念更容易落地了.比如我们说的CI,CD,CD a.CI(Continuous Integration):持续集成 b.CD( ...

  4. flash文件上传下载组件

    以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传  ...

  5. learning java AWT 剪贴板 传递文本

    import javax.swing.*; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.dat ...

  6. uic

    uic user interface complieruic mainwindow.ui >> ui_mainwidow.h

  7. 汇编语言笔记 CALL和RET指令

    转载地址:http://www.cnblogs.com/dennisOne ☞模块化程序设计 模块化程序设计 汇编语言通过call和ret指令实现了模块化程序设计.可以实现多个相互联系.功能独立的子程 ...

  8. codevs 5972 格子游戏

    5972 格子游戏  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description Alice和Bob玩了一个古老的游戏:首先画一个n * ...

  9. PKUSC2019 改题记录

    PKUSC2019 改题记录 我真的是个sb... 警告:不一定是对的... D1T1 有一个国家由\(n\)个村庄组成,每个村庄有一个人.对每个\(i\in[1,n-1],\)第\(i\)个村庄到第 ...

  10. Java 日期工具类(日期,月份加减等)--转

    package util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.C ...