I - Chips Moving

You are given n chips on a number line. The i-th chip is placed at the integer coordinate xi. 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 i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate xi with xi−2 or with xi+2);
move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate xi with xi−1 or with xi+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 n chips to the same coordinate (i.e. all xi should be equal after some sequence of moves).

Input

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

The second line of the input contains n integers x1,x2,…,xn (1≤xi≤109), where xi is the coordinate of the i-th chip.

Output

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

Examples

Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
看不懂吧哈哈我也看不懂,下面是翻译:
题意:
你在数轴上有n个筹码。第i个芯片放置在整数坐标xi处。一些芯片可以有相等的坐标。
您可以执行以下两种类型的移动任何(可能,零)次数在任何芯片:
将芯片i向左移动2个单位或向右移动2个单位(即将当前坐标xi替换为xi - 2或xi+2);
将芯片i向左移动1个单位,或向右移动1个单位,并为此支付一枚硬币(即将当前坐标xi替换为xi−1或xi+1)。
注意,它允许将芯片移动到任何整数坐标,包括-和0。
你的任务是找到移动所有n个筹码到同一坐标所需的最小硬币总数(即所有xi应该在一些步骤后相等)。
输入:
输入的第一行包含一个整数n(1≤n≤100)——芯片的数量。
输入的第二行包含n个整数x1,x2,…,xn(1≤xi≤109),其中xi为第i个芯片的坐标。
输出:
106/5000
打印一个整数-移动所有n个筹码到同一坐标所需的最小硬币总数。

概括:

题意:给n个木片,放在坐标Xi上,要将所有木片移动到同一个坐标, 使得花费最少。

有两种移法:1、每次移动2个位置不用花钱 。2、每次移动1个位置花1块钱。

思路

不管怎么样移动,最后都是移动到同一个位置,这个位置分两种情况:1.这个位置坐标为奇数2.这个位置坐标为偶数
如果是奇数,则奇数坐标的物体移动的距离是2的倍数,也就是不需要钱,偶数移动的距离是2的倍数加一,所以每个偶数坐标的物体要以一块钱。
如果是偶数,则反之。
所以这道题就在于看是偶数多还是奇数多。偶数多则移动到一个偶数位置,反之,移动到一个奇数位置。``

#include<stdio.h>
int main()
 {
int n,x[101],a=0,b=0,sum,i;
scanf("%d", &n);
for(i=1;i<=n;i++)
{
	scanf("%d", &x[i]);
}
for(i=1;i<=n;i++)
{
	if(x[i]%2==0)
	a++;
	else
	b++;
}
if(a>b)  //取一个偶数坐标,只需要b个奇数坐标物体每个花一块钱 
sum=b*1;
else     //反之去一个奇数坐标 
sum=a*1;
printf("%d\n", sum);
	 return 0;
 }
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值