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 ...
随机推荐
- 通过swagger将API业务版本号与Gitlab代码版本号绑定
1.调用Gitlab API获取项目commit ID 2.编辑 Swagger2.java @Configuration @EnableSwagger2 @EnableWebMvc public c ...
- 【代码笔记】Web-HTML-基础
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- 【读书笔记】iOS-Web应用程序的自动化测试
seleniumHQ:https://github.com/seleniumhq/selenium Appium:https://github.com/appium/appium 参考资料:<i ...
- 两年AI研究经验(教训)总结,进来看看吧!
https://www.jianshu.com/p/2149c9fee166 摘要: 本文以过来人的身份将自身2年的研究经验做了一下分享,希望本文对于即将开始从事人工智能研究的朋友有所帮助. 人工智能 ...
- 机器学习算法(SVM)公开课4月25日开讲
从深蓝到AlphaGo,聪明的人工智能一再“羞辱”人类大脑: 指纹识别.以图搜图.语音助手.无人驾驶···生活里它无孔不入 离不开智能手机的我们,是否已开始被人工智能的“奴役”? 或许,你不需要会运用 ...
- Flutter 布局(六)- SizedOverflowBox、Transform、CustomSingleChildLayout详解
本文主要介绍Flutter布局中的SizedOverflowBox.Transform.CustomSingleChildLayout三种控件,详细介绍了其布局行为以及使用场景,并对源码进行了分析. ...
- (后端)sql server 按时间段查询
百度的资料,保存下来: 在写按时间段查询的sql语句的时候 一般我们会这么写查询条件: where date>='2010-01-01' and date<='2010-10-1'. 但是 ...
- [20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED.txt
[20180317]12c TABLE ACCESS BY INDEX ROWID BATCHED.txt --//简单探究12c TABLE ACCESS BY INDEX ROWID BATCHE ...
- if条件简单语法
if语句是实际工作中最重要最常用的语句. if条件语法: 单分支结构 if [ 条件 ] then 指令 fi 或 if [ 条件 ]:then 指令 fi if 单分支条件中文编程形象语法: 如果 ...
- Debian-Linux配置网卡网络方法
Debian不同于centos系统,网卡配置不是在/etc/sysconfig/network-scrip里面,而是在/etc/network/interfaces里面 1.Debian网络配置 配置 ...