题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6227
解析:给你n个位置,选其中一个往另外其它两个位置的中间插,问能插几次
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[509], b[509];
int main()
{
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
int ans = 0;
for(int i = 2; i <= n; i++)
{
b[i-1] = a[i]-a[i-1]-1;
ans += b[i-1];
}
int k = min(b[1], b[n-1]);
printf("%d\n", ans - k);
}
return 0;
}