题目链接:
PREV-5 错误票据
思路:
等差数列求和再相减即可得到缺失的;
重复的用map记录下即可;
代码:
#include<bits/stdc++.h>
using namespace std;
typedef map<int, int>::iterator IT;
int main() {
#ifdef MyTest
freopen("Sakura.txt", "r", stdin);
#endif
map<int, int> mp;
int x, mn = 1 << 30, mx = -1;
scanf("%d", &x);
while(~scanf("%d", &x)) ++mp[x], mn = min(mn, x), mx = max(mx, x);
int a = (mn + mx) * (mx - mn + 1) / 2, b;
for(IT it = mp.begin(); it != mp.end(); it++) {
if(it->second == 2) b = it->first;
a -= it->first;
}
printf("%d %d", a, b);
return 0;
}