Description
There is an integer array A1, A2 ...AN. Each round you may choose two adjacent integers. If their sum is an odd number, the two adjacent integers can be deleted.
Can you work out the minimum length of the final array after elaborate deletions?
Input
The first line contains one integer N, indicating the length of the initial array.
The second line contains N integers, indicating A1, A2 ...AN.
For 30% of the data:1 ≤ N ≤ 10
For 60% of the data:1 ≤ N ≤ 1000
For 100% of the data:1 ≤ N ≤ 1000000, 0 ≤ Ai ≤ 1000000000
Output
One line with an integer indicating the minimum length of the final array.
Sample Hint
(1,2) (3,4) (4,5) are deleted.
Sample Input
7
1 1 2 3 4 4 5
Sample Output
1
There is an integer array A1, A2 ...AN. Each round you may choose two adjacent integers. If their sum is an odd number, the two adjacent integers can be deleted.
Can you work out the minimum length of the final array after elaborate deletions?
Input
The first line contains one integer N, indicating the length of the initial array.
The second line contains N integers, indicating A1, A2 ...AN.
For 30% of the data:1 ≤ N ≤ 10
For 60% of the data:1 ≤ N ≤ 1000
For 100% of the data:1 ≤ N ≤ 1000000, 0 ≤ Ai ≤ 1000000000
Output
One line with an integer indicating the minimum length of the final array.
Sample Hint
(1,2) (3,4) (4,5) are deleted.
Sample Input
7
1 1 2 3 4 4 5
Sample Output
1
解析:我们首先要知道这个数的集合,删除到最后必定不会出现任意两个数和是奇数,因为一个奇数加偶数的和必定是奇数,则说明这个数的集合中一定只存在偶数或者奇数(否则一定会有一个奇数与偶数相挨着),这就只用计算出偶数个数与奇数个数的差的绝对值。
#include<cstdio>
#include<algorithm>
#include<cmath>
int main(){
int data,amount;
int sum1 = 0, sum2 = 0, sum;
scanf("%d", &amount);
while(amount--){
scanf("%d",&data);
if(data%2 == 0){
sum1++;
}
else{
sum2++;
}
}
sum=fabs(sum1 - sum2);
printf("%d\n",sum);
return 0;
}