Gym - 101911I Heist (签到题)

There was an electronic store heist last night.
All keyboards which were in the store yesterday were numbered in ascending order from some integer number
x
x
. For example, if
x=4
x=4
and there were
3
3
keyboards in the store, then the devices had indices
4
4
,
5
5
and
6
6
, and if
x=10
x=10
and there were
7
7
of them then the keyboards had indices
10
10
,
11
11
,
12
12
,
13
13
,
14
14
,
15
15
and
16
16
.
After the heist, only
n
n
keyboards remain, and they have indices
a
1
,
a
2
,…,
a
n
a1,a2,…,an
. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither
x
x
nor the number of keyboards in the store before the heist.
Input
The first line contains single integer
n
n
(1≤n≤1000)
(1≤n≤1000)
— the number of keyboards in the store that remained after the heist.
The second line contains
n
n
distinct integers
a
1
,
a
2
,…,
a
n
a1,a2,…,an
(1≤
a
i

10
9
)
(1≤ai≤109)
— the indices of the remaining keyboards. The integers
a
i
ai
are given in arbitrary order and are pairwise distinct.
Output
Print the minimum possible number of keyboards that have been stolen if the staff remember neither
x
x
nor the number of keyboards in the store before the heist.
Examples
Input
4
10 13 12 8
Output
2
Input
5
7 5 6 4 8
Output
0
Note
In the first example, if
x=8
x=8
then minimum number of stolen keyboards is equal to
2
2
. The keyboards with indices
9
9
and
11
11
were stolen during the heist.
In the second example, if
x=4
x=4
then nothing was stolen during the heist.
问题链接: http://codeforces.com/gym/101911/problem/I
问题简述: 给定n个数字,求最大数字与最小数字的之间没有出现的数字个数
问题分析: 如题意一样简单,ans=max-min+n-1
AC通过的C++语言程序如下:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#define ll long long
#define endl '\n'
#include<ctime>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    ll minx=99999999999;
    ll maxx=-99999999999;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k;
        if(k>maxx)
            maxx=k;
        if(k<minx)
            minx=k;
    }
    //cout<<maxx<<" "<<minx<<endl;
    cout<<maxx-minx+1-n;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44012745/article/details/89073786