Hdu 6227 Rabbits
来源:互联网 发布:Python Max iteritem 编辑:程序博客网 时间:2024/06/07 03:21
Rabbits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 126 Accepted Submission(s): 75
Problem Description
Here N (N ≥ 3) rabbits are playing by the river. They are playing on a number line, each occupying a different integer. In a single move, one of the outer rabbits jumps into a space between any other two. At no point may two rabbits occupy the same position.
Help them play as long as possible
Help them play as long as possible
Input
The input has several test cases. The first line of input contains an integer t (1 ≤ t ≤ 500) indicating the number of test cases.
For each case the first line contains the integer N (3 ≤ N ≤ 500) described as above. The second line contains n integersa1 < a2 < a3 < ... < aN which are the initial positions of the rabbits. For each rabbit, its initial position
ai satisfies 1 ≤ ai ≤ 10000.
For each case the first line contains the integer N (3 ≤ N ≤ 500) described as above. The second line contains n integers
Output
For each case, output the largest number of moves the rabbits can make.
Sample Input
533 4 632 3 533 5 941 2 3 441 2 4 5
Sample Output
11301
AC代码:
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int N = 500 + 10;int s[N];int main(){int t;scanf("%d", &t);while(t--){int n;scanf("%d", &n);memset(s, 0, sizeof(s));for(int i = 1; i <= n; i++){scanf("%d", &s[i]);}//printf("%d %d", maxn, minn);int ans1 = 0;for(int i = 2; i < n; i++){ans1 = ans1 + s[i + 1] - s[i] - 1;}int ans2 = 0;for(int i = n - 1; i > 1; i--){ans2 = ans2 + s[i] - s[i - 1] - 1;}int ans = max(ans1, ans2);printf("%d\n", ans);}return 0;}
阅读全文
0 0
- hdu 6227 Rabbits
- Hdu 6227 Rabbits
- Rabbits —— HDU-6227
- hdu 4452 Running Rabbits
- hdu 4452 Running Rabbits
- HDU Running Rabbits(模拟)
- hdu 4452 Running Rabbits
- hdu - 4452 - Running Rabbits
- HDU-4745-Two Rabbits
- hdu 4745 Two Rabbits
- HDU 4745 Two Rabbits
- HDU 4745 Two Rabbits
- hdu 4745 Two Rabbits
- hdu 4745 Two Rabbits
- HDU - 4745 Two Rabbits
- hdu 4452 Running Rabbits
- HDU 4745 Two Rabbits
- hdu 4452 Running Rabbits
- SpringBoot入门
- ArrayList、LinkedList、Vector的区别
- HDU-1022 火车进出站问题【栈】
- [置顶] 基于深度学习的色情视频鉴定
- SSL2839 2017年11月6日提高组T1 游戏(dp)
- Hdu 6227 Rabbits
- 百度
- springmvc加载jsp
- Fuc和Action的使用
- kubernetes日志采集与解析
- java(十五):concurrent(0)—AtomicInteger,Unsafe,CAS
- win10 x64安装xgboost错误解决
- oracle:时区
- linux入门-python多版本切换