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;
    }




  • 相关阅读:
    lsblk---列出所有可用块设备的信息,
    blkid---对系统块设备信息查询
    du---是对文件和目录磁盘使用的空间查看
    strings---对象文件或二进制文件中查找可打印的字符串
    which---查找并显示给定命令的绝对路径
    whereis---定位指令的二进制程序、源代码文件和man手册页等相关文件的路径。
    cd---切换工作目录
    cp---复制文件
    ls---显示文件目录各项信息
    pwd---以绝对路径的方式显示用户当前工作目录
  • 原文地址:https://www.cnblogs.com/lklk/p/8986258.html
Copyright © 2011-2022 走看看