4416. 缺少的数
给定一个长度为 n1 的数列 a1,a2,…,an1。
数列中的元素两两不同,且都在 1~n 的范围内。
请你计算,1~n 中的哪一个数没有在数列中出现过。
输入格式
第一行包含一个整数 n。
第二行包含 n1 个整数 a1,a2,…,an1。
输出格式
输出 1~n 中没有在数列中出现过的数。
数据范围
前三个测试点满足 2≤n≤10。
所有测试点满足 2≤n≤105,1≤ai≤n。
输入样例:
10
3 8 10 1 7 9 6 5 2
输出样例:
4
思路
哈希或等差数列公式
哈希代码
哈希
输入的数都标记一下,输入完成之和遍历即可
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include<tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
typedef