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 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
随机推荐
- [20170603]12c Top Frequency histogram.txt
---恢复内容开始--- [20170603]12c Top Frequency histogram.txt --//个人对直方图了解很少,以前2种直方图类型对于目前的许多应用来讲已经足够,或者讲遇到 ...
- c/c++ lambda 表达式 剖析
lambda 表达式 剖析 大前提:捕获列表里变量的确定时机. 捕获列表和参数列表有区别,捕获列表里的变量,是在捕获的时间点就确定了,而不是在lambda调用时确定,参数列表是在调用时才确定.所以当捕 ...
- nmap参数原理抓包分析
nmap参数原理抓包分析 实验环境: Nmap7.70 实验步骤: 1.主机发现 2.端口扫描 3.服务版本探测 一.主机发现 主机发现,如果主机活跃,扫描1000个常用的tcp端口 1.Nmap i ...
- git 使用命令删除远程分支和本地分支
删除远程分支命令: git push origin :<远程分支名称> git push origin --delete <远程分支名称> 删除本地分支: git bran ...
- git笔记(2)-常见命令的使用(详解待续)
1. 常用命令 (1)git --help 帮助命令,其他的类似 (2)git branch 查看分支及其他(创建分支,查看远程分支名称等) (3)git checkout 切换分支以及其他 (3)g ...
- eclipse版本对应名称以及下载地址
Eclipse 1.0 2001年11月7日(Win32/Linux32 Motif) Eclipse 2.0 2002年6月27日(Linux32 Motif ...
- python + MySql 基本操作
python + mysql数据库的链接 1.安装mysql pip install PySQLdb 2.连接数据库 # -*- coding: UTF- -*- import MySQLdb # 打 ...
- 【算法】LeetCode算法题-Merge Two Sorted List
这是悦乐书的第148次更新,第150篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第7题(顺位题号是21).合并两个已排序的链表并将其作为新链表返回. 新链表应该通过拼接 ...
- Loj #2731 「JOISC 2016 Day 1」棋盘游戏
Loj 2731 「JOISC 2016 Day 1」棋盘游戏 JOI 君有一个棋盘,棋盘上有 \(N\) 行 \(3\) 列 的格子.JOI 君有若干棋子,并想用它们来玩一个游戏.初始状态棋盘上至少 ...
- UVA12113-Overlapping Squares(二进制枚举)
Problem UVA12113-Overlapping Squares Accept:116 Submit:596 Time Limit: 3000 mSec Problem Descripti ...