hiho一下 第200周 题目1 : Shortening Sequence

 
                                                                                                 Shortening Sequence
 
时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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?

输入

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

输出

One line with an integer indicating the minimum length of the final array.

样例提示

(1,2) (3,4) (4,5) are deleted.

样例输入
7
1 1 2 3 4 4 5
样例输出
1

《Shortening Sequence》题目分析

本题是说给定一个数组,如果两个相邻的数和是奇数,就可以把这两个数一起删除。问如果精心设计删除的话,最终最少剩下几个数。

我们知道如果和是奇数,那么这两个数一定是一奇一偶。如果最后只剩下奇数或者只剩下偶数,那么一定不能继续删除了。

同时,如果数组中还同时存在奇数和偶数,那么一定有两个相邻的整数是一奇一偶。换句话说,只要数组中还同时存在奇数和偶数,就一定可以继续进行删除。

所以本题的结论就比较明显了。答案就是数组中奇数和偶数的数量差。

没错,就是这样。。。。感觉被gg了,下面贴一波代码,超短

#include <iostream>
#include<cmath>
using namespace std;

int main()
{
 int n;
 int a;
 int ou=0,ji=0;
 scanf("%d",&n);
 for(int i=0;i<n;i++)
 {
  scanf("%d",&a);
  if(a%2==0)
  ou++;
  else
  ji++;
 }
 printf("%d\n",abs(ji-ou));
 return 0;
}




posted on 2018-05-03 16:53 Azure╰ 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lklk/p/8986258.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值