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 ...
随机推荐
- webservice的一些理解
web services中如果用.NET的话,DataSet可以作为与客户端交互的一个返回值,因为DataSet实质上是XML.而SOAP WSDL等都是基于XML的. --------------- ...
- [19/06/08-星期六] CSS基础_表格&表单
一.表格 如生活中的Excel表格,用途就是同来表示一些格式化的数据,如课程表.工资条.成绩单. 在网页中也可以创建出不同的表格,在HTML中使用table标签来创建一个表格.table是个块元素. ...
- 思维体操: HDU1008 Elevator
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- ModelForm操作
ModelForm a. class Meta: model, # 对应Model的 fields=None, # 字段 exclude=None, # 排除字段 labels=None, # 提示信 ...
- maven联通网络下中央仓库不能访问的解决办法
最近刚开始学习maven工具,下载解压完毕,环境变量配置完毕,运行如下命令尝试快速构建一个maven项目: mvn archetype:generate 结果就有问题: [INFO] Scanning ...
- Xcode 运行时异常
一:unable to boot the ios simulator:模拟器异常 1.在添加了新的xcode版本调试包时,出现旧版模拟器不支持的情况,关闭旧版模拟器,重新运行 二:Could not ...
- egretios包接微信/facebook登录
ios包有了,现在需要登录,就先使用微信登录吧,后继加一个facebook登录. 根据我的理解,先预测一下应该是怎么回事吧. 首先应该是要去微信的公共平台注册一下,说我的应用是什么应用,要填写企业信息 ...
- grep 查找文件
--递归查找目录下含有该字符串的所有文件 grep -rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/ ...
- VS 2012 Unit Test
1,Open Tool->Custmoize 2,Create Unit Tests Move Down Run Test 3,Restart run VS 4,Create UnitTest ...
- 如何设置Linux虚拟机的IP地址
本文会详细的解释如何在Linux虚拟机下设置IP地址 我的虚拟机是CentOS 首先,打开你的虚拟机 1.修改主机名 修改完主机名之后,别忘了用:wq命令保存退出 然后我们来设置虚拟机的IP地址 首先 ...