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