原题链接: https://codeforces.com/problemset/problem/1041/A
测试用例
input
4
10 13 12 8
output
2
input
5
7 5 6 4 8
output
0
Note
在第一个样例中,如果 x = 8 那么最小的失窃题数是 2。 编号为 9 和 11 的题在盗窃中被偷了。
在第二个样例中,如果 x = 4 则没有题被偷
题意: 给出仍然存在的签到题数量和编号,现在需要你找出被盗的最小数量题。
解题思路: 我们知道签到题是连续编号的,故我们要使得补最小的题目,我们就要使得被盗数量最小,即使得这些签到题编号的界限就为 [ 最 小 编 号 : 最 大 编 号 ] [最小编号:最大编号] [最小编号:最大编号]。那么这些题目是要连续的,故我们需计算的值即为这个区间长度减去原题数数量。
AC代码
/*
*邮箱:[email protected]
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int n;
int a[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>n){
rep(i,0,n-1){
cin>>a[i];
}
sort(a,a+n);
int temp=a[n-1]-a[0]+1;
cout<<temp-n<<endl;
}
return 0;
}