zoukankan      html  css  js  c++  java
  • 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 ",abs(ji-ou));
     return 0;
    }




  • 相关阅读:
    UI是一个状态机
    WPF : Binding的3个属性: Source, RelativeSource, ElementName
    业务驱动设计
    WPF : 对Collection要注意重用子控件
    WPF : UserControl的Initialized事件不会触发
    mvc3上传图片
    MVC3.0自定义视图引擎(切换皮肤)
    ASP.NET MVC 多语言解决方案
    键盘键位表
    Silverlight之IsolatedStorageSettings对象
  • 原文地址:https://www.cnblogs.com/lklk/p/8986258.html
Copyright © 2011-2022 走看看