E. Boxers
给定N个数字,每个数字可以加一或者减一
使得结果集合中不同数字个数最多
贪心
用桶装数
假如相同的数字$i$超过三个,则上面$i+1$,下面$i-1$都可以分一个
如果相同数字$i$只有两个,优先$i-1$
如果只有一个也要优先$i-1$
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<4*N;i++) scanf("%I64d",&A[i]);
#define P pair<ll,ll>
ll N;
ll q;
ll A[];
bool B[];
int main()
{
sc(N);
for(int i=; i<N; i++)
{
sc(q);
A[q]++;
}
for(int i=; i<=; i++)
{
if(A[i]>=)
{
if(i>)
{
// A[i-1]++;
B[i-]=;
}
B[i]=;
B[i+]=;
}
else if(A[i]==)
{
if(i>&&B[i-]==)
{
B[i-]=;
}
else if(B[i+]==)
{
B[i+]=;
}
B[i]=;
}
else if(A[i]==)
{
//cout<<i<<B[i]<<endl;
if(i>&&B[i-]==)B[i-]=;
else if(B[i]==)B[i+]=;
else B[i]=;
}
}
int ans=;
for(int i=; i<=; i++)
{
if(B[i]){ans++;//cout<<i<<endl;
} }
cout<<ans<<'\n';
}
E. Boxers的更多相关文章
- CF #579 (Div. 3) E.Boxers
E.Boxers time limit per test2 seconds memory limit per test256 megabytes inputstdin outputstdout The ...
- Codeforces Round #579 (Div. 3) E. Boxers (贪心)
题意:给你一组数,每个数都可以进行一次加一减一,问最后最多能有多少不同的数. 题解:我们可以用桶存每个数的次数,然后枚举\([1,150001]\)来求对答案的贡献,然后贪心,这里我们不用担心其他乱七 ...
- bootstrap-validator使用
bootstrap-validator是一款与bootstrap相结合的表单前端验证模块,官方网址:http://1000hz.github.io/bootstrap-validator/ 下面内容大 ...
- 1.1 NCE21 Daniel Mendoza
1.text translation Two hundred years ago, boxing matches were very popular in England. At that time/ ...
- NCE3
Lesson1 A puma at large Pumas are large, cat-like animals which are found in America. When reports ...
- New Concept English three(21)
27W 59 Boxing matches were very popular in England two hundred years ago. In those days, boxers foug ...
- lesson 21 Daniel Mendoza
lesson 21 Daniel Mendoza bare 赤裸的 :boxers fought with bare fists crude 天然的:crude sugar, crude oil 粗俗 ...
- codeforces #579(div3)
codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...
- Codeforces Round #579 (Div. 3)
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...
随机推荐
- Environment Modules简单使用
Environment Modules简单使用 Environment Modules简介 Typically users initialize their environment when they ...
- 解决react项目中跨域和axios封装使用
最新几天学了一下react,发现了几个问题,估计新入坑的同学们也会遇到,下面我先列出来几点 1.请求跨域问题 2.如何发起请求 3.axios的简单封装 全局安装create-react-app脚手架 ...
- Grafana配置文件
配置文件位置 /usr/local/opt/grafana/share/grafana/default.ini /usr/local/etc/grafana/grafana.ini 配置文件调用顺序 ...
- debian上安装mysql server
1 将mysql添加到apt的repository中 第一步,下载mysql提供的ppa文件 wget https://dev.mysql.com/get/mysql-apt-config_0.8.1 ...
- fidder抓包工具使用方法,完整流程
fidder抓包工具使用方法,完整流程 https://blog.csdn.net/lw545034502/article/details/82150779 版权声明:本文为博主原创文章,遵循 CC ...
- Xdex(百度版)脱壳工具基本原理
[原创]Xdex(百度版)脱壳工具基本原理作 者: sherrydl时 间: 2015-12-13,10:52:45链 接: http://bbs.pediy.com/showthread.php?t ...
- leetcode第一题(easy)
第一题:题目内容 Given an array of integers, return indices of the two numbers such that they add up to a sp ...
- UITableViewCell选中后子View背景色被Clear
在TableView中,当cell 处于Hightlighted(高亮)或者Selected(选中)状态下,Cell上的子控件的背景颜色会被 Clear. 解决方法:(4种) 1. 直接设置子控件的 ...
- verilog中的timescale
`timescale是Verilog HDL 中的一种时间尺度预编译指令,它用来定义模块的仿真 时的时间单位和时间精度.格式如下: `timescale 仿真时间单位/时间精度 注意:,不能为其它的 ...
- PAT Basic 1036 跟奥巴马一起编程 (15 分)
美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014 年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个 ...