【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 ...
随机推荐
- 【数据库】2.0 MySQL入门学习(二)——如何获得MySQL以及MySQL安装
1.0 如何获得MySQL: www.oracle.com https://dev.mysql.com/downloads/ 2.0 例如进入Oracle官网,找到MySQL: 进入页面后,切换到“资 ...
- 创建Python数据分析的Docker镜像+Docker自定义镜像commit,Dockerfile方式解析+pull,push,rmi操作
实例解析Docker如何通过commit,Dockerfile两种方式自定义Dcoker镜像,对自定义镜像的pull,push,rmi等常用操作,通过实例创建一个Python数据分析开发环境的Dock ...
- C++基础--static的用法
首先,看看变量的存储: int global ; int main() { int stackStore ; int heapStore* = (int *)malloc(sizeof(int)); ...
- arcgis版接合图表5.2 免费软件,支持国家2000坐标系,ArcGIS10.0,ArcGIS10.1,ArcGIS10.2都可以使用
下载地址:http://files.cnblogs.com/gisoracle/jionmap52.rar 1. 国家2000,西安80,北京54.坐标系的接合图表生成.根据经纬度范围,坐标 ...
- Android StickHeaderRecyclerView - 让recyclerview头部固定
介绍在项目中有时会需要recyclerview滑动式时某个view滑出后会固定在头部显示,比较常用的比如手机联系人界面.地区选择界面等. StickHeaderRecyclerView就是实现这个功能 ...
- JS高级程序设计第三版——JavaScript简介
JavaScript简史 JavaScript由Netscape(网景)公司在1995年发布,最开始的主要目的是处理以前由服务器端语言负责的一些输入验证操作,以便提高用户体验,后来就慢慢的发展为一门强 ...
- PHP 数字转汉字函数
/** * 数字转汉字描述 */ function numToStr($num) { // 判断正确数字 if (!preg_match('/^(\d*)(\.\d+)?$/', $num)) ret ...
- Business Component(BC)和Business Object(BO)
Siebel应用架构的一个成功的地方就是在应用里引入了BC,BO的概念,从而使得几千张关系数据表能够按照业务的含义组织成业务对象,对于业务人员而言具有了业务上的含义,而不仅仅是从技术人员的观点来对待数 ...
- 关于rapidxml无法解析中文路径问题
先放结果 setlocale(LC_ALL, ""); rapidxml::file<> f(szPath); setlocale(LC_ALL, "C&qu ...
- 【[SDOI2008]洞穴勘测】
题目 由于始终保证连通性于是我们可以用\(LCT\)来维护这个森林 三个操作分别是\(link,cut,findroot\) 代码 #include<iostream> #include& ...