AtCoder Beginner Contest 053
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
5
1 2 1 3 7
Sample Output 1
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: 1, 3 and 7.
Sample Input 2
15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
Sample Output 2
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的更多相关文章
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
随机推荐
- Linux CFS调度器之pick_next_task_fair选择下一个被调度的进程--Linux进程的管理与调度(二十八)
1. CFS如何选择最合适的进程 每个调度器类sched_class都必须提供一个pick_next_task函数用以在就绪队列中选择一个最优的进程来等待调度, 而我们的CFS调度器类中, 选择下一个 ...
- Elixir 单元测试
概述 elixir 中自带了单元测试框架 ExUnit ,其中提供单元测试的一系列,主要包含以下模块: ExUnit: 单元测试框架 ExUnit.Assertions: 断言 ExUnit.Case ...
- HBase数据库相关基本知识
HBase数据库相关知识 1. HBase相关概念模型 l 表(table),与关系型数据库一样就是有行和列的表 l 行(row),在表里数据按行存储.行由行键(rowkey)唯一标识,没有数据类 ...
- 《Java大学教程》—第11章 案例研究--第1部分
自测题:1. 图11-1的UML设计中各个类之间的关系.Hostel与TenantList是关联关系:TenantList和PaymentList与ObjectList是泛化关系.TenantL ...
- 第一次使用Open Live Writer维护BlogJava
换了电脑,又重装了一堆东西,现在才把Open Live Writer整好.顺便记下几个心得: Open Live Writer已经没办法从网站上下载了,介绍个方法,可以把地址直接拷贝到迅雷里面,然后请 ...
- UEditor学习笔记1
首先对于前段时间遇到的一些总结做下记录: 0 == '' => true transition,渐变属性,其值可以是某属性,也可以是all,如transition: all 0.3s:鼠标放到 ...
- vue源码分析—模板解析
福建省啦剑飞傻了剑飞撒到了看风景啊撒:
- [ZJOI2012]灾难
嘟嘟嘟 偶尔翻到的一道题. 50分暴力很好想,对于每一个点进行一次拓扑排序,然后每一次别memset,只清空走过的点,能拿到70分. 正解好像也挺好想,是一个叫"灭绝树"的东西. ...
- ubantu搭建oj——第一天(6.11)
oj第一份作业: 按照DMOJ的文档将代码搬运到ubantu上 sudo apt install git gcc g++ make python-dev libxml2-dev libxslt1-de ...
- pytorch visdom可视化工具学习—1—详细使用-1—基本使用函数
使用教程,参考: https://github.com/facebookresearch/visdom https://www.pytorchtutorial.com/using-visdom-for ...