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. Robot Framework Webdriver For Firefox FQA

    记录一下过程中使用的问题,希望大家碰到类似问题能够提高效率解决. 问题1.通过js脚本定位unieap框架网页中radio选项. 通过执行js脚本获取radio选项,并通过xpath路径点击. js脚 ...

  2. 设计模式之序章-UML类图那点事儿

    设计模式之序-UML类图那点事儿 序 打14年年底就像写那么一个系列,用于讲设计模式的,代码基于JAVA语言,最早接触设计模式是大一还是大二来着,那时候网上有人给推荐书,其中就有设计模式,当时给我推荐 ...

  3. 使用 Bullet,BulletManager 在 XNA 中创建子弹攻击目标(十五)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  4. git:多个sshkey配置

    克隆项目: 使用git clone +项目.git地址 例如: 创建SSH Key: ssh-keygen -t rsa -C +邮箱地址 sshkey自定义保存:创建后在第二步(enter file ...

  5. selenium 浏览器驱动下载地址

    谷歌浏览器驱动下载http://chromedriver.storage.googleapis.com/index.html 火狐浏览器驱动下载http://ftp.mozilla.org/pub/f ...

  6. git基础之常用操作

    一.版本提交: (1)git add 文件名 (2)git commit -m "版本提交信息" 注:git分两个区:工作区+版本库 在电脑中看到的文件夹就是工作区 有一个隐藏的. ...

  7. 聊聊、Tomcat中文乱码和JVM设置

    set JAVA_OPTS=%JAVA_OPTS% -server -Xms512m -Xmx512m -Dfile.encoding=GBK -Dsun.jnu.encoding=GBK

  8. (转载) Linux五种IO模型

    转载:http://blog.csdn.net/jay900323/article/details/18141217     Linux五种IO模型及分析   目录(?)[-] 概念理解 Linux下 ...

  9. [atcoder002E] Candy Piles [博弈论]

    题面: 传送门 思路: 每一堆糖排成一列,所有列横着放,形成一个阶梯型 两个决策相当于左边一列去掉和最下面一行去掉 那么这个模型可以转化为同样形状的网格图,向左上方走,走到边界的赢· 然后一波数学推导 ...

  10. cf 843 B Interactive LowerBound [随机化]

    题面: 传送门 思路: 这是一道交互题 比赛的时候我看到了直接跳过了...... 后来后面的题目卡住了就回来看这道题,发现其实比较水 实际上,从整个序列里面随机选1000个数出来询问,然后从里面找出比 ...