1.0题目
zls有n个薯条,第i个薯条的位置在xi,一些薯条可能放在相同的位置上。
你可以进行任意次(包括0次)如下操作:
1.不花费任何钱,把薯条i的位置左移2或右移2,即xi加2或减2;
2.花费一元,把薯条i的位置左移1或右移1,把xi加1或减1;
请找出让所有薯条移动到同一位置花费的最少价格(即所有的xi最后都要相同)。
Input
第一行输入一个n(1<=n<=100),代表薯条的数量。
第二行输入n个整数x1,x2,…,xn(1<=xi<10^9),xi代表薯条的坐标位置。
Output
输出把n个薯条都移动到同一位置所花费的最小价格。
Examples
Input
3
6 5 4
Output
1
Input
5
7 7 6 6 6
Output
2
Note
在第一个例子中,你需要将第一个薯条向右移动2,将第二个薯条向右移动1,或者将第三个薯条向左移动2,将第二个薯条向左移动1,这样答案就是1。
在第二个例子中,你需要移动两个坐标为7的筹码,所以答案是2。
2.0代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100 + 10;
int a[maxn],b[maxn];
int main()
{
int n,sum=0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] = a[i] % 2;
b[a[i]]++;
}
if (b[1] ==n|| b[0] == n)
{
cout << 0 << endl;
return 0;
}
else
{
int ans = min(b[1], b[0]);
cout << ans << endl;
}
return 0;
}