2017 ACM/ICPC 沈阳 K题 Rabbits

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

InputThe 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 a1a1 < a2a2 < a3a3 < ... < aNaN which are the initial positions of the rabbits. For each rabbit, its initial position 
aiai satisfies 1 ≤ aiai ≤ 10000. 
OutputFor 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签到题:Orz
#include<bits/stdc++.h>
using namespace std;
int T,num[510],sum[510];
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int len=0;
        for(int i=1;i<=n;i++) scanf("%d",&num[i]);
        for(int i=1;i<n;i++) sum[i]=num[i+1]-num[i]-1,len+=sum[i];
        int ans=len-min(sum[1],sum[n-1]);
        printf("%d\n",ans);
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/songorz/p/9784969.html

时间: 2024-10-28 10:41:52

2017 ACM/ICPC 沈阳 K题 Rabbits的相关文章

2017 ACM/ICPC 沈阳 F题 Heron and his triangle

A triangle is a Heron's triangle if it satisfies that the side lengths of it are consecutive integers t−1, t, t+ 1 and thatits area is an integer. Now, for given n you need to find a Heron's triangle associated with the smallest t bigger than or equa

2017 ACM/ICPC 沈阳 L题 Tree

Consider a un-rooted tree T which is not the biological significance of tree or plant, but a tree as an undirected graph in graph theory with n nodes, labelled from 1 to n. If you cannot understand the concept of a tree here, please omit this problem

2017 acm icpc 沈阳(网络赛)5/12 题解

比赛中较...能做的5道题 hdoj6195. cable cable cable 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6195 题目大意 : 略 规律 : 答案 = k+(m-k)*k hdoj6198. number number number 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6198 题目大意  : 给你一个整数n.问你n个斐波那契数(可重复)不能构成哪些数,输出

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 1496    Accepted Submission(s): 723 Problem Description Kelukin is a businessman. Every day, he travels arou

2017 acm / icpc shenyang 双十一单身狗温馨重现赛

上午做实验老师看错时间来晚了,20与非门一侧坏掉..于是做完实验就,光荣迟到了!!!QAQ... 一开始..看B题...喵喵喵??? J题...窝只会暴力..算了算了.. 刷新~ I题AC ratio 好像还可以!戳进去一看,a+b+c+d...一克斯Q斯咪?哭叽叽写了个大数加法,piapiapia乱敲一气竟然没崩,AC~~~是个好开头吖有木有~o(* ̄▽ ̄*)ブ~ K题就是小兔子跳啊跳~piapiapia求和然后选择一下从哪一端起跳,紫欣sama1A~ L题一开始对题意有误解,看懂样例之后就发

HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)

题目链接  2017 CCPC Harbin Problem K 题意  给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_{i}}$的最小值. 首先二分答案,那么每个物品的权值就变成了$x * b_{i} - a_{i}$ 在判断的时候先把那些权值为正的物品全部选出来, 然后记录一下从$1$开始可以覆盖到的最右端点的位置. 接下来开始DP,按照区间的端点升序排序(左端点第一关键字,右端点第二关键字) 问题转化为能否用剩

2017 ACM/ICPC 新疆赛区 I 题 A Possible Tree 带权并查集

传送门 题意:给定一棵带权树的形态, 但是并不知道每天条边的具体权重. 然后给m个信息, 信息格式为u v val, 表示在树上u 到 v 的路径上经过的边的权重的异或和为val, 问前面最多有多少个信息是不冲突的. 思路:首先很明显的我们要维护一系列不知道的信息, 看冲不冲突的那就是带权并查集没跑了, 此时r[v] 表示v到这棵树的根节点(虽然题目没给, 但是我们可以假设一个)的路径异或和, 那么此时的每条信息相当于是告诉你r[u] ^ r[v]的值, 注意异或的特性. 所以对于每条信息维护好

2017 ACM/ICPC Asia Regional Shenyang Online 部分刷题记录

cable cable cable 题意: M个灯,K个盒子,求最少要连多少条线,使任选K个盒子每个灯都能装下 思路: 每个灯要连(M-K+1)个 总共M*(M-K+1) happy happy happy 题意: 左右取数,孩子每次都去左右两边最大的那个,父亲想让孩子赢(大于父亲)且最小化分差 思路: 限时搜索,先dp预处理出l,r区间最大分差和最小分差,然后\(2^n\)搜索,但每进入一层都要利用dp数组更新一次答案 #include<bits/stdc++.h> #define pii