PAT A1144 The Missing Number (20 分)——set
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 (≤105). 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
#include <stdio.h>
#include <algorithm>
#include <limits.h>
#include <set>
using namespace std;
int main() {
int n;
scanf("%d", &n);
set<int> st;
for (int i = ; i < n; i++) {
int tmp;
scanf("%d", &tmp);
if (tmp > ) {
st.insert(tmp);
}
}
int j = ;
for (auto it = st.begin(); it != st.end(); it++) {
if (*it > j) {
printf("%d", j);
break;
}
else j++;
}
if(j==st.size()+)printf("%d",j);
}
注意点:这里只保证了输入数不超过int大小,用hash不好做,不如直接用set,自动升序排列,找到第一个不满足的数。
第二个坑是测试点2-5都是输入数据连续的,缺失的是输入数据后面那个数
PAT A1144 The Missing Number (20 分)——set的更多相关文章
- PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)
1144 The Missing Number (20 分) Given N integers, you are supposed to find the smallest positive in ...
- PAT A1019 General Palindromic Number (20 分)
AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...
- PAT 1144 The Missing Number
1144 The Missing Number (20 分) Given N integers, you are supposed to find the smallest positive in ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT乙级:1088 三人行 (20分)
PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...
- PAT乙级:1064 朋友数 (20分)
PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...
- [PAT] 1144 The Missing Number(20 分)
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 1144 The Missing Number[简单]
1144 The Missing Number(20 分) Given N integers, you are supposed to find the smallest positive integ ...
随机推荐
- Apollo源码阅读笔记(一)
Apollo源码阅读笔记(一) 先来一张官方客户端设计图,方便我们了解客户端的整体思路. 我们在使用Apollo的时候,需要标记@EnableApolloConfig来告诉程序开启apollo配置,所 ...
- Starting zookeeper ... already running as process 1805错误
启动zookeeper的时候,报Starting zookeeper ... already running as process 1805错误 上面这个错误意思为以作为进程1805运行.系统检测到你 ...
- Spark调优_性能调优(一)
总结一下spark的调优方案--性能调优: 一.调节并行度 1.性能上的调优主要注重一下几点: Excutor的数量 每个Excutor所分配的CPU的数量 每个Excutor所能分配的内存量 Dri ...
- HTML meta头部小结
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python 简单的远程执行命令
client端执行命令,server端返回命令结果 # server 端 import socket, subprocess sk = socket.socket() address=('127.0. ...
- jQuer插件满屏气泡飘落动画效果
飘落动画效果插件引用: <script src="https://cdn.bootcss.com/JQuery-Snowfall/1.7.4/snowfall.jquery.min.j ...
- demo:复制粘贴功能
复制链接功能,也是为了方便用户一键"复制",粘贴链接和文本到指定位置,在此,接着上一篇"demo:生成专属二维码link "来记录一键"复制" ...
- 【读书笔记】iOS-iOS视频
视频多媒体文件主要是存放视频数据信息,视频数据量要远远大于音频数据文件,而且视频编码和解码算法非常复杂,因此早期的计算机由于CPU处理能力差,要采用视频解压卡硬件支持,视频采集和压缩也要采用硬件卡.按 ...
- Python 利用Python操作excel表格之xlwt介绍
利用Python操作excel表格之xlwt介绍 by:授客 QQ:1033553122 直接上代码 案例1 #!/usr/bin/env python # -*- coding:utf-8 ...
- Linux 设备树的解释 - DTB文件格式【转】
https://blog.csdn.net/cc289123557/article/details/51782449 1.dtb文件格式 dtb文件的格式如下图 : NOTE:不同部分顺序可能不一样 ...