zoukankan      html  css  js  c++  java
  • 2017微软秋招A题

    时间限制: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


    题解:此题有一点需注意,删除后的元素不影响周围的元素(例如删除23元素,14元素就变得相邻了)
    法1.理解了这一点,用个栈或向量直接两两判断

    法2.由于奇数与偶数和才为奇数,奇数偶数成对消除,所以本题目可以用奇数与偶数的差的绝对值直接计算。
  • 相关阅读:
    ? ?? 类?
    类 建索引
    访问局域网计算机文件
    JS 在元素后面添加新的元素
    js 网页加载完毕,执行js函数
    设置快捷键(3种方式)
    winform设置textbox设置水印
    ADO.NET 学生管理
    C#整理 条件语句
    ADO.NET 数据访问类查询、属性扩展
  • 原文地址:https://www.cnblogs.com/wangkundentisy/p/5947744.html
Copyright © 2011-2022 走看看