CF985A.Chess Placing

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".

Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .

In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.

Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

给你一个大小为 1×n1 \times n 的棋盘。保证 nn 是偶数。棋盘的着色方式如下:“BWBW...BW”。

棋盘上某些格子被棋子占据。每个格子至多有一个棋子。已知棋子的总数等于 。

每一步操作中,你可以将某个棋子向左或向右移动一格。你不能将棋子移出棋盘边界,也不能将棋子移动到已被占据的格子上。

你的任务是用最少的移动步数,将所有棋子都放置在同一种颜色的格子上(即:所有棋子最终必须全部位于黑色格子上,或全部位于白色格子上)。

输入格式

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.

The second line of the input contains integer numbers (1 ≤ p__i ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

输入的第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100,且 nn 为偶数)—— 表示棋盘的大小。

输入的第二行包含 n2\frac{n}{2} 个整数 pip_i(1≤pi≤n1 \leq p_i \leq n)—— 表示棋子的初始位置。保证所有位置互不相同。

输出格式

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

输出一个整数——将所有棋子移动到同一种颜色的格子中所需的最少移动次数。

输入输出样例

  • 输入#1

    6
    1 2 6

    输出#1

    2
  • 输入#2

    10
    1 2 3 4 5

    输出#2

    10

说明/提示

In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.

In the second example the possible strategy is to move in 4 moves, then in 3 moves, in 2 moves and in 1 move.

在第一个例子中,唯一可行的策略是将位于位置 6 的棋子移动到位置 5,并将位于位置 2 的棋子移动到位置 3。注意:若你选择将棋子放置在白色格子中,则最少移动次数为 3。

在第二个例子中,一种可行的策略是:将 在 4 步内移动,然后将 在 3 步内移动,将 在 2 步内移动,最后将 在 1 步内移动。

输入解题思路,AI测评打分。不知道怎么写?

首页