CF1213A.Chips Moving

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn chips on a number line. The ii-th chip is placed at the integer coordinate xix_i. Some chips can have equal coordinates.

You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:

  • Move the chip ii by 22 to the left or 22 to the right for free (i.e. replace the current coordinate xix_i with xi−2x_i - 2 or with xi+2x_i + 2);
  • move the chip ii by 11 to the left or 11 to the right and pay one coin for this move (i.e. replace the current coordinate xix_i with xi−1x_i - 1 or with xi+1x_i + 1).

Note that it's allowed to move chips to any integer coordinate, including negative and zero.

Your task is to find the minimum total number of coins required to move all nn chips to the same coordinate (i.e. all xix_i should be equal after some sequence of moves).

你被给定数轴上的 nn 个筹码。第 ii 个筹码位于整数坐标 xix_i 处。某些筹码的坐标可能相同。

你可以对任意一个筹码执行以下两种操作中的任意一种,且每种操作可以执行任意次数(包括零次):

  • 免费将筹码 ii 向左或向右移动 22 个单位(即:将当前坐标 xix_i 替换为 xi−2x_i - 2 或 xi+2x_i + 2);
  • 将筹码 ii 向左或向右移动 11 个单位,并为此支付一枚硬币(即:将当前坐标 xix_i 替换为 xi−1x_i - 1 或 xi+1x_i + 1)。

注意:允许将筹码移动到任意整数坐标,包括负数和零。

你的任务是求出使所有 nn 个筹码到达同一坐标(即:经过若干次操作后,所有 xix_i 均相等)所需的最少硬币总数。

输入格式

The first line of the input contains one integer nn (1≤n≤1001 \le n \le 100) — the number of chips.

The second line of the input contains nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (1≤xi≤1091 \le x_i \le 10^9), where xix_i is the coordinate of the ii-th chip.

输入的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示芯片的数量。

输入的第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \dots, x_n(1≤xi≤1091 \le x_i \le 10^9),其中 xix_i 表示第 ii 个芯片的坐标。

输出格式

Print one integer — the minimum total number of coins required to move all nn chips to the same coordinate.

输出一个整数——将所有 nn 个筹码移动到同一坐标所需的最少硬币总数。

输入输出样例

  • 输入#1

    3
    1 2 3

    输出#1

    1
  • 输入#2

    5
    2 2 2 3 3

    输出#2

    2

说明/提示

In the first example you need to move the first chip by 22 to the right and the second chip by 11 to the right or move the third chip by 22 to the left and the second chip by 11 to the left so the answer is 11.

In the second example you need to move two chips with coordinate 33 by 11 to the left so the answer is 22.

在第一个例子中,你需要将第一个筹码向右移动 22 个单位,第二个筹码向右移动 11 个单位;或者将第三个筹码向左移动 22 个单位,第二个筹码向左移动 11 个单位,因此答案为 11。

在第二个例子中,你需要将两个坐标为 33 的筹码各自向左移动 11 个单位,因此答案为 22。

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

首页