【2017 ICPC亚洲区域赛沈阳站 K】Rabbits(思维)
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
Sample Output
题意:
有n只兔子在不同的位置,任意一只最外面的兔子可以跳到其余任意两只兔子中间空位里,问所有兔子最多可移动的总次数。
思路:
只要最外面的两只兔子中,有一只兔和其他兔相邻,即它们之间没有空格,那么最大可移动次数就是剩下的空格数之和。
那么问题就很简单了,就判断一下位于端点的两只兔子与它们最近兔子之间的距离,取相对距离小的一组,用总空格数-该组之间的空格数即可。
#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(思维)的更多相关文章
- 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)
		
Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...
 - 2014ACM/ICPC亚洲区域赛牡丹江站汇总
		
球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...
 - ACM-ICPC 2016亚洲区域赛(沈阳站)游记(滚粗记)
		
首发于QQ空间和知乎,我在这里也更一下. 前言 以前高中搞竞赛的时候,经常看到神犇出去比赛或者训练之后写游记什么的,感觉萌萌哒.但是由于太弱,就没什么心情好写.现在虽然还是很弱,但是抱着享受的心情 ...
 - 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation
		
Known Notation Time Limit: 2 Seconds Memory Limit: 65536 KB Do you know reverse Polish notation ...
 - 【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 ...
 - 【2018 ICPC亚洲区域赛南京站 A】Adrien and Austin(博弈)
		
题意: 有一排n个石子(注意n可以为0),每次可以取1~K个连续的石子,Adrien先手,Austin后手,若谁不能取则谁输. 思路: (1) n为0时的情况进行特判,后手必胜. (2) 当k=1时, ...
 - 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-A ( ZOJ 3819 ) Average Score
		
Average Score Time Limit: 2 Seconds Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...
 - 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)
		
Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...
 - 【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 ...
 
随机推荐
- 重构指南 - 封装集合(Encapsulate Collection)
			
封装就是将相关的方法或者属性抽象成为一个对象. 封装的意义: 对外隐藏内部实现,接口不变,内部实现自由修改. 只返回需要的数据和方法. 提供一种方式防止数据被修改. 更好的代码复用. 当一个类的属性类 ...
 - java编程中'为了性能'一些尽量做到的地方
			
原文地址:http://blog.csdn.NET/m13666368773/article/details/7796924 最近的机器内存又爆满了,出了新增机器内存外,还应该好好review一下我们 ...
 - ARM-IoT
			
http://tech.hqew.com/fangan_723798 物联网就是一个物品互联网,这里的物品(物)内部有电子系统,具有感知和上报功能,支持远程控制,有时还能做出简单的决策.与物联网相关的 ...
 - IoT Architecture
 - .NET开源工作流RoadFlow-表单设计-数据表格
			
数据表格即在表单中显示一个table,该table数据可以来自任意自定义的来源: 数据类型:指定表格的数据源类型 1.datatable,即.net中的System.Data.DataTable 2. ...
 - Jmeter各部件的作用
			
JMeter主要组件介绍 1.测试计划(Test Plan)是使用 JMeter 进行测试的起点,它是其它 JMeter 测试元件的容器. 2.线程组(Thread Group)代表一定数量的并发用户 ...
 - 30分钟LINQ教程 【转载】
			
原文地址:http://www.cnblogs.com/liulun/archive/2013/02/26/2909985.html 在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有 ...
 - monkeyrunner多点触摸
			
思路是:在屏幕上某个位置按着不放:device.touch(x,y,md.DOWN) 然后再做一个滑动的操作:device.drap((x1,y1),(x2,y2),0.2,10) 然后再松开按键:d ...
 - Angular5+ 自定义表单验证器
			
Angular5+ 自定义表单验证器 Custom Validators 标签(空格分隔): Angular 首先阐述一下遇到的问题: 怎样实现"再次输入密码"的验证(两个cont ...
 - php之Apache压力测试
			
1,测试本机是否已经安装好Apache ①进入自己的Apache目录下面的bin目录,然后执行ab -V.如果返回Apache版本则表示已经装好 2,执行压力测试命令,ab -n 1000(请求总数) ...