博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hiho一下 第200周 题目1 : Shortening Sequence
阅读量:4313 次
发布时间:2019-06-06

本文共 1302 字,大约阅读时间需要 4 分钟。

 
                                                                                                
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.

样例输入
71 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 阅读(
...) 评论(
...)

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

你可能感兴趣的文章
百度搜索引擎取真实地址-python代码
查看>>
java 多线程 Future callable
查看>>
字符串操作练习:星座、凯撒密码、99乘法表
查看>>
Java实现字符串转换十六进制MD5值
查看>>
MySQL数据库8(十七)数据库的备份还原
查看>>
tensorflow 梯度下降以及summary
查看>>
9、接口和抽象类
查看>>
timeStamp和GMT时间的转换
查看>>
探索J2ME应用:如何用GCF通信
查看>>
jquery ajaxform上传文件返回不提示信息的问题
查看>>
实现一个2008serve的IIS的虚拟目录(通过网络路径(UNC)的形式,共享在另外一个2008服务器上...
查看>>
适配器
查看>>
c#截取字符串
查看>>
VS2005中配置 ScriptManager,UpdatePanel,UpdateProgress 等AJAX控件 .
查看>>
使用logback实现http请求日志导入mongodb
查看>>
【 2017 Multi-University Training Contest - Team 9 && hdu 6162】Ch’s gift
查看>>
redis在php中的应用(Hash篇)
查看>>
Docker系列之Docker镜像(读书笔记)
查看>>
Scrapy 多url爬取、爬取post请求、更换代理ip、指定日志等级
查看>>
phpExcel实现excel文件导出
查看>>