Chess Placing
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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).

Input

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 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

Output

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

Examples
input

Copy
6
1 2 6
output

Copy
2
input

Copy
10
1 2 3 4 5
output

Copy
10
Note

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.

两种情况分别跑一遍,求最少

#include <iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007;
using namespace std;
int main()
{
int n;
std::cin>>n;
int a[];
for(int i=;i<=n/;i++)
{
std::cin>>a[i];
}
sort(a+,a++n/);
int s1=;
int s2=;
int c1=;
int c2=;
for(int i=;i<=n/;i++,c1+=,c2+=)
{
s1+=abs(a[i]-c1);
s2+=abs(a[i]-c2);
}
s1=min(s2,s1);
std::cout<<s1;
return ;
}

codeforce 985A Chess Placing(暴力)的更多相关文章

  1. codeforces 985A Chess Placing

    题意: 移动最少的步数,使得所有的棋子在同一颜色的格子中. 每次一个棋子只能向左或者向右移动一步,不能移到有棋子的格子中. 思路: 枚举全黑和全白的情况. 对于每一个需要移动的棋子,它移动到的位置一定 ...

  2. A - Chess Placing CodeForces - 985A

    You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted ...

  3. codeforce Number of Ways(暴力)

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  4. A. Chess Placing

    链接 [https://codeforces.com/contest/985/problem/A] 题意 给你一个偶数n,输入n/2个数,代表棋子的位置,有一个1*n的棋盘是黑白相间的 问你使得所有棋 ...

  5. CF985A Chess Placing【思维】

    [链接]:CF985A [题意]:给你n和n/2个数ai,每个ai和奇数.偶数比较距离(注意选了奇数,偶数的距离就不要算了,反之同理),求最小的答案. [代码]: #include <iostr ...

  6. Educational Codeforces Round 44 (Rated for Div. 2)

    题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...

  7. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  8. CodeForce 855B 暴力or线段树

    CodeForce 855B 暴力or线段树 题意 给你一串数,然后找出三个数,他们的前后关系和原来一样,可以相同,然后分别乘p,q,r,求他们积的和最大,并且输出这个数. 解题思路 这个可以使用线段 ...

  9. codeforce 429D. Tricky Function (思维暴力过)

    题目描述 Iahub and Sorin are the best competitive programmers in their town. However, they can't both qu ...

随机推荐

  1. SSH2 增删查改实例

    (一)引入包 (共73个,不一定都需要,但是我的项目是这么多,经过调试,没有包冲突) (二)创建数据库表 建立数据库octtest,并创建user表,表里面一共4个字段:id,姓,名,年龄. 语句如下 ...

  2. JNIjw01

    1.VC6(CPP)的DLL代码: #include<stdio.h> #include "jniZ_JNIjw01.h" JNIEXPORT void JNICALL ...

  3. Java小程序之回文数字

    题目:一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. 下面是代码: package test; public class BackNum { public st ...

  4. 三十五 Python分布式爬虫打造搜索引擎Scrapy精讲—scrapy分布式爬虫要点

    1.分布式爬虫原理 2.分布式爬虫优点 3.分布式爬虫需要解决的问题

  5. PetaPoco入门

    (转自:http://www.cnblogs.com/tinyhu/archive/2013/06/02/3113652.html) 1. ORM概括 1.1. ORM简介 ORM 对象-关系映射(O ...

  6. 封装hibernate中session(静态单例模式)

    因为每次用增删改查时都需要用到session,直接做一个类,需要的时候只需要调用即可 import org.hibernate.Session; import org.hibernate.Sessio ...

  7. UI- 基础控件零散知识点回归

    1.frame\center\bounds 1> frame:能修改位置和尺寸 2> center:能修改位置 3> bounds:能修改尺寸(x\y一般都是0) 2.在.m中声明的 ...

  8. <input type="checkbox" name="" value=" ">

    <input type="checkbox"  name=""  value=" ">

  9. Lua学习---编译生成lua和luac

    众所周知,Lua是一种强大的脚本语言,并且这种语言是用C语言实现的.为什么要学习这门语言?因为它可以增强我看C语言代码的功底. 我下的Lua版本是Lua5.3,关于Lua5.3的简介如下: http: ...

  10. mac root

    我在mac下,用su登录root用户 但是提醒 su:Sorry   然后按照网上的方法弄了好多次,都没成功,说是要修改/etc/group 文件中,wheel后添加自己的用户名,用逗号分隔多个用户, ...