Rabbits

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1193    Accepted Submission(s): 628

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
 
Source
 
 
 
 
代码:
 1 #include<bits/stdc++.h>
2 using namespace std;
3 const int N=1e5+10;
4 const int INF=0x3f3f3f3f;
5 int flag[N];
6 int a[N];
7 int main(){
8 int t,n,minn;
9 int num1,num2,num;
10 while(~scanf("%d",&t)){
11 while(t--){
12 scanf("%d",&n);
13 memset(flag,0,sizeof(flag));
14 for(int i=0;i<n;i++){
15 scanf("%d",&a[i]);
16 flag[a[i]]=1;
17 }
18 num1=0,num2=0,num=0;
19 for(int i=a[0];i<=a[1];i++){
20 if(flag[i]==0)num1++;
21 }
22 for(int i=a[n-2];i<=a[n-1];i++){
23 if(flag[i]==0)num2++;
24 }
25 for(int i=a[0];i<=a[n-1];i++){
26 if(flag[i]==0)num++;
27 }
28 //cout<<num1<<" "<<num2<<" "<<num<<endl;
29 minn=min(num1,num2);
30 printf("%d\n",num-minn);
31 }
32 }
33 return 0;
34 }

HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))的更多相关文章

  1. HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O ...

  2. 2017ACM/ICPC亚洲区沈阳站-重现赛

    HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...

  3. 2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    Little Boxes Problem Description Little boxes on the hillside.Little boxes made of ticky-tacky.Littl ...

  4. 2016ACM/ICPC亚洲区沈阳站-重现赛赛题

    今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...

  5. hdu 5510 Bazinga (kmp+dfs剪枝) 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    废话: 这道题很是花了我一番功夫.首先,我不会kmp算法,还专门学了一下这个算法.其次,即使会用kmp,但是如果暴力枚举的话,还是毫无疑问会爆掉.因此在dfs的基础上加上两次剪枝解决了这道题. 题意: ...

  6. 2016ACM/ICPC亚洲区沈阳站-重现赛

    C.Recursive sequence 求ans(x),ans(1)=a,ans(2)=b,ans(n)=ans(n-2)*2+ans(n-1)+n^4 如果直接就去解...很难,毕竟不是那种可以直 ...

  7. 2015ACM/ICPC亚洲区沈阳站重现赛-HDU5512-Pagodas-gcd

    n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, l ...

  8. 2015ACM/ICPC亚洲区沈阳站-重现赛 M - Meeting (特殊建边,最短路)

    题意:有\(n\)个点,\(m\)个集合,集合\(E_i\)中的点都与集合中的其它点有一条边权为\(t_i\)的边,现在问第\(1\)个点和第\(n\)个点到某个点的路径最短,输出最短路径和目标点,如 ...

  9. 2015ACM/ICPC亚洲区沈阳站-重现赛 B - Bazinga (KMP)

    题意:给你\(n\)个字符串,\(s_1,s_2,...,s_n\),对于\(i(1\le i\le n)\),找到最大的\(i\),并且满足\(s_j(1\le j<i)\)不是\(s_i\) ...

随机推荐

  1. C++多态实例

    #include <iostream> #include <string> using namespace std; //class 实现 class Employee { s ...

  2. Gym - 101981D Country Meow(模拟退火)

    题意 三维空间有\(n\)个点,找到另外一个点,离所有点的最大距离最小.求这个距离. 题解 \(1\).最小球覆盖,要找的点为球心. \(2\).模拟退火. 还是补一下模拟退火的介绍吧. 模拟退火有一 ...

  3. HDOJ 2120 Ice_cream's world I

    Ice_cream's world I ice_cream's world is a rich country, it has many fertile lands. Today, the queen ...

  4. NOI p 2017 TG游记

    嗨小朋友们大家好 还记得我是谁吗 对了我就是为iot配音的演员 弹鸡鸡 今天呐我特别的要向长沙市的oier们 洛谷的oier们 还有cnblogs的oier们问声好 为什么呢 因为我们在2017年11 ...

  5. laravel5.2总结--ORM模型

    ORM模型简介 1>什么是ORM? ORM,即 Object-Relational Mapping(对象关系映射),它的作用是在关系型数据库和业务实体对象之间作一个映射,这样,我们在操作具体的 ...

  6. 48、android代码架构总结

    之前是按功能模块进行分类,现在随着功能模块越来越多,代码层次不再清晰,所以修改了工程结构: 之前: 经过修改现在: 1.更严谨的遵循mvc架构 bean目录存放的是数据模型 ui存储的是activit ...

  7. leetcode 【 Subsets II 】python 实现

    题目: Given a collection of integers that might contain duplicates, S, return all possible subsets. No ...

  8. git+jenkins持续集成三-定时构建语法

    构建位置:选择或创建工程_设置_构建触发器 1. 定时构建语法:* * * * * (五颗星,多个时间点,中间用逗号隔开)第一个*表示分钟,取值0~59第二个*表示小时,取值0~23第三个*表示一个月 ...

  9. 聊聊、Spring 数据源

    平时开发中我们每天都会跟数据库打交道,页面上显示的数字,图片,语音,等等都存在某个地方,而我们就是要从那个地方拿到我们想要的.现在存储数据的方式越来越多,多种多样,但用的最多的还是关系数据库.Spri ...

  10. 在数组中寻找出现次数大于N/K的数

    给定一个int[]数组,给定一个整数k,打印所有出现次数大于N/k的数,没有的话,给出提示信息. === 核心思想:一次在数组中删除K个不同的数,不停的删除,直到剩下的数的种类不足K就停止删除,那么如 ...