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的更多相关文章

  1. CF #579 (Div. 3) E.Boxers

    E.Boxers time limit per test2 seconds memory limit per test256 megabytes inputstdin outputstdout The ...

  2. Codeforces Round #579 (Div. 3) E. Boxers (贪心)

    题意:给你一组数,每个数都可以进行一次加一减一,问最后最多能有多少不同的数. 题解:我们可以用桶存每个数的次数,然后枚举\([1,150001]\)来求对答案的贡献,然后贪心,这里我们不用担心其他乱七 ...

  3. bootstrap-validator使用

    bootstrap-validator是一款与bootstrap相结合的表单前端验证模块,官方网址:http://1000hz.github.io/bootstrap-validator/ 下面内容大 ...

  4. 1.1 NCE21 Daniel Mendoza

    1.text translation Two hundred years ago, boxing matches were very popular in England. At that time/ ...

  5. NCE3

    Lesson1  A puma at large Pumas are large, cat-like animals which are found in America. When reports ...

  6. New Concept English three(21)

    27W 59 Boxing matches were very popular in England two hundred years ago. In those days, boxers foug ...

  7. lesson 21 Daniel Mendoza

    lesson 21 Daniel Mendoza bare 赤裸的 :boxers fought with bare fists crude 天然的:crude sugar, crude oil 粗俗 ...

  8. codeforces #579(div3)

    codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...

  9. Codeforces Round #579 (Div. 3)

    Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...

随机推荐

  1. Docker开启ssh服务

    一.准备 apt-get update       更新环境 apt-get install vim      安装vim vim  /etc/apt/source.list     更换软件源, 我 ...

  2. 第六周总结&第四次实验报告

    实验四 类的继承 一. 实验目的 (1) 掌握类的继承方法: (2) 变量的继承和覆盖,方法的继承.重载和覆盖实现: 二. 实验内容 三.实验过程 实验代码 package Shiyan4; publ ...

  3. 006 Notepad++ 运行 C/C++

    目录 0. 前言 1. 准备 2. 开工 setp 1 step 2 step 3 step 4 step 5 step 6 3. 修改与删除 3.1修改名称.快捷键 3.2 删除 4. 运行 5. ...

  4. 替换url不刷新页面

    今天碰到一个有趣的问题, 从其他站点登录后,放回了一个token, 但是我切换了路由之后token还在, 路由直接跟在了token参数后面, 后面先利用location.href替换掉原来的连接, 但 ...

  5. 逆向工程 生成mapper 接口的 重要方法

    @Test public void testSelectByExample() { ItemsExample itemsExample = new ItemsExample(); ItemsExamp ...

  6. python UnicodeEncodeError: 'gbk' codec can't encode character ...

    使用Python写文件的时候,或者将网络数据流写入到本地文件的时候,大部分情况下会遇到:UnicodeEncodeError: 'gbk' codec can't encode character ' ...

  7. 最长上升子序列(LIS) Easy

    A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given ...

  8. Java的同名属性、同名普通函数、同名静态函数,是否被覆盖

    作者按:虚拟函数的概念早就滚瓜烂熟了.但是今天面试发现:1.同名属性,2.同名普通函数,3.同名静态函数,是否被覆盖的问题.请看下面三个例子: 例子1:测试父类的属性是否存在和被完全覆盖class A ...

  9. 在Visual studio 2017中使用EF6连接MySQL

    在Visual studio 2017中使用EF6连接Mysql ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) ...

  10. CSS选择符有哪些?哪些属性可以继承

    下面是一些常用的选择器: 1.id选择器( # myid) 2.类选择器(.myclassname) 3.标签选择器(div, h1, p) 4.相邻选择器(h1 + p) 5.子选择器(ul > ...