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.

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 integers a1 < a2 < a3 < ... < aN which are the initial positions of the rabbits. For each rabbit, its initial position
ai satisfies 1 ≤ ai ≤ 10000.

Output

For each case, output the largest number of moves the rabbits can make.

Sample Input

5
3
3 4 6
3
2 3 5
3
3 5 9
4
1 2 3 4
4
1 2 4 5

Sample Output

1
1
3
0
1

题意:

有n只兔子在不同的位置,任意一只最外面的兔子可以跳到其余任意两只兔子中间空位里,问所有兔子最多可移动的总次数。

思路:

只要最外面的两只兔子中,有一只兔和其他兔相邻,即它们之间没有空格,那么最大可移动次数就是剩下的空格数之和。

那么问题就很简单了,就判断一下位于端点的两只兔子与它们最近兔子之间的距离,取相对距离小的一组,用总空格数-该组之间的空格数即可。

题目链接:HDOJ 6227

#include<iostream>
#include<algorithm>
#define MAX 505
using namespace std;
int main()
{
    int t,n,i,a[MAX];
    cin>>t;
    while(t--)
    {
        cin>>n;
        ;i<=n;i++)
            cin>>a[i];
        ;
        ;i<=n;i++)
            sum=sum+a[i]-a[i-]-;
        ]-a[]-;
        ]-;
        cout<<sum-min(head,tail)<<endl;
    }
    ;
}

【2017 ICPC亚洲区域赛沈阳站 K】Rabbits(思维)的更多相关文章

  1. 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)

    Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...

  2. 2014ACM/ICPC亚洲区域赛牡丹江站汇总

    球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...

  3. ACM-ICPC 2016亚洲区域赛(沈阳站)游记(滚粗记)

    首发于QQ空间和知乎,我在这里也更一下.   前言 以前高中搞竞赛的时候,经常看到神犇出去比赛或者训练之后写游记什么的,感觉萌萌哒.但是由于太弱,就没什么心情好写.现在虽然还是很弱,但是抱着享受的心情 ...

  4. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation

    Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation ...

  5. 【2017 ICPC亚洲区域赛北京站 J】Pangu and Stones(区间dp)

    In Chinese mythology, Pangu is the first living being and the creator of the sky and the earth. He w ...

  6. 【2018 ICPC亚洲区域赛南京站 A】Adrien and Austin(博弈)

    题意: 有一排n个石子(注意n可以为0),每次可以取1~K个连续的石子,Adrien先手,Austin后手,若谁不能取则谁输. 思路: (1) n为0时的情况进行特判,后手必胜. (2) 当k=1时, ...

  7. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-A ( ZOJ 3819 ) Average Score

    Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...

  8. 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)

    Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...

  9. 【2018 ICPC亚洲区域赛徐州站 A】Rikka with Minimum Spanning Trees(求最小生成树个数与总权值的乘积)

    Hello everyone! I am your old friend Rikka. Welcome to Xuzhou. This is the first problem, which is a ...

随机推荐

  1. [转]MySQL索引类型

    此为转载文章,仅做记录使用,方便日后查看,原文链接:https://www.cnblogs.com/luyucheng/p/6289714.html MySQL索引类型   一.简介 MySQL目前主 ...

  2. Spring课程 Spring入门篇 5-1 aop基本概念及特点

    概念: 1 什么是aop及实现方式 2 aop的基本概念 3 spring中的aop 1 什么是aop及实现方式 1.1 aop,面向切面编程,比如:唐僧取经需要经过81难,多一难少一难都不行.孙悟空 ...

  3. 运行jsp时,报错404

    The origin server did not find a current reprsentation for the target resource or is not willing to ...

  4. 【Linux】Windows与Linux之间的文件共享(基于网络)

    切记:Linux的安全机制的存在--iptables和selinux. 一.操作前提 1.1 从Windows能够ping通Linux 1.2 关闭Linux防火墙 command1:/etc/ini ...

  5. WebSettings 最全属性说明

    setAllowContentAccess (boolean allow) 是否允许在WebView中访问内容URL(Content Url),默认允许.内容Url访问允许WebView从安装在系统中 ...

  6. wxpython Menus and toolbars

    Menus and toolbars A common part in a GUI application is a menubar. A menubar consists of objects ca ...

  7. LAMP专业术语的规范书写格式

    DIV+CSS(技术) MySQL(数据库) Sphinx(中文分词技术) JavaScript(语言) MySQLi(MySQL数据库连接方式) MongoDB(NoSQL数据库) Ajax(Jav ...

  8. 使用文档碎片(DocumentFragments)追加DOM元素

    标签(空格分隔): JavaScript DocumentFragment接口表示一个没有父级文件的最小文档对象.它被当做一个轻量版的Document使用,用于存储已排好版的或尚未打理好格式XML片段 ...

  9. dedecms 权重排序问题

    isweight='y' orderway='asc'  orderby='weight'  依次进入根目录>dede 找到打开文件 album_edit.php   //找到更新数据库的SQL ...

  10. 服务器常用命令之 启用/禁用PING状态

    启用 echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all  (PING的通) 禁用 echo 1 > /proc/sys/net/ipv4/i ...