D - Card Eater


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer Ai is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

  • 3≦N≦105
  • N is odd.
  • 1≦Ai≦105
  • Ai is an integer.

Input

The input is given from Standard Input in the following format:

N
A1 A2 A3 ... AN

Output

Print the answer.


Sample Input 1

Copy
5
1 2 1 3 7

Sample Output 1

Copy
3

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 13 and 7.


Sample Input 2

Copy
15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

Copy
7

题目大意:

给你N个卡片,每次操作可以任意拿三个卡片出来,去掉最大值和最小值的卡片,中间值卡片放回去。

问最多可以剩余几张卡片,并且使得不重复。

重复的序列,难道你没有点想法吗?

大佬的思考:序列中一直抽重复的直接去掉,最后变成变成一个012的序列,对于2的序列,只要有两个2的序列,我就可以变成两个1,这样最后判断是否有2剩余即可

这样就解释了最优的结构,我们知道最优结构就是看是否余2,换而言之,就是判断序列不重复个数是奇数还是偶数.偶数一定需要删除一个

#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#include<stdio.h>
using namespace std;
int main(){
int tmp;
int n;
while(~scanf("%d",&n)){
map<int,int> a;
for (int i=1;i<=n;i++){
scanf("%d",&tmp);
a[tmp]++;
}
int k=a.size();
if (k%2==1)printf("%d\n",k);
else printf("%d\n",k-1);
}
return 0;
}

  

AtCoder Beginner Contest 053的更多相关文章

  1. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  2. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  3. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

随机推荐

  1. Vue2 学习笔记3

    文中例子代码请参考github 定义Vue组件 什么是组件: 组件的出现,就是为了拆分Vue实例的代码量的,能够让我们以不同的组件,来划分不同的功能模块,将来我们需要什么样的功能,就可以去调用对应的组 ...

  2. cmd是命令提示符吗?

    经常使用电脑的小伙伴对cmd有所了解,它能帮我们快速解决问题.搜索框中输入“cmd”,就可以看到命令提示符程序了.那么,命令提示符程序和cmd到底有着什么样的联系呢?下面就为大家讲解一下. CMD是c ...

  3. Linux 小知识翻译 - 「代理服务器」

    这回聊聊「代理服务器」. 在公司里,不通过代理服务器无法连接互联网的,由于代理服务器的原因,有些服务的使用是受到限制的. 有人可能会觉得为什么会存在这种东西?(这里指代理服务器) Proxy本来的意思 ...

  4. Docker: docker image常用命令实战

    #docker列出镜像[root@192 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 881bd08c0b08 ...

  5. 【ctags/cscope/project安装使用】给神编辑器vim添加新的翅膀

    本文地址 分享提纲: 1.安装 2.使用cscope 3.使用project 1.安装 1.1)linux(yum下安装) yum -y install cscope 1.2)linux(unbunt ...

  6. 04.Python网络爬虫之requests模块(1)

    引入 Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用. 警告:非专业使用其他 HTTP 库会导致危险的副作用,包括:安全缺陷症.冗余代码症.重新发明轮子症.啃文档 ...

  7. Teradata的DBQL使用

    1.赋权 grant exec on DBC.DBQLAccessMacro to Sysdba with grant option; 2.刷新DBQL或TDWM缓存到磁盘,立即能在数据库中查询到刚刚 ...

  8. mysql 数据库基础命令

    数据库命令: 进入 mysql 库; use mysql; 查看用户权限 select * from user where user='root' \G; 创建数据库 create database ...

  9. Vim怎么批量处理文件将tab变为space

    :%s/\t/    /g https://zhidao.baidu.com/question/563849372716100364.html

  10. Mac中selenium使用出现错误

    解决方案是: 首先通过brew 安装 $ brew install geckodriver 然后设置配置文件~/.bash_profile文件 export PATH=$PATH:/path/to/g ...