305174: CF985A. Chess Placing

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Chess Placing

题意翻译

有一个形如“黑白黑白黑白……”的1×n的棋盘(n是2的倍数),棋盘上有n/2个棋子,每次可以将一个棋子移至相邻的一个没有棋子的格子,告诉你棋盘的大小n和所有棋子所在的位置p1,p2,...,pn/2,问至少需要几次才能使所有棋子所在的格子颜色一样。 2<=n<=100,n是偶数

题目描述

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 ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/e98ace5c1ad627053f6404505602ba90672a171b.png). 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).

输入输出格式

输入格式


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 ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/e98ace5c1ad627053f6404505602ba90672a171b.png) integer numbers ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/f69846f45d2fb290f17c0996035d8272d32fce7d.png) ( $ 1<=p_{i}<=n $ ) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

输出格式


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 ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/4f3653422b6429c3f89311497c438fd20547c4f8.png) in 4 moves, then ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/6c4181624e2b8f95750df668d534111d8ee2005d.png) in 3 moves, ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/74a8630d5d683f941562dca49b5d40bcde2fe1ef.png) in 2 moves and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF985A/b97ec32af1cd5347877d0d15bd3de6cc845fde76.png) in 1 move.

Input

题意翻译

有一个形如“黑白黑白黑白……”的1×n的棋盘(n是2的倍数),棋盘上有n/2个棋子,每次可以将一个棋子移至相邻的一个没有棋子的格子,告诉你棋盘的大小n和所有棋子所在的位置p1,p2,...,pn/2,问至少需要几次才能使所有棋子所在的格子颜色一样。 2<=n<=100,n是偶数

加入题单

上一题 下一题 算法标签: