E. Boxers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are ?
boxers, the weight of the ?-th boxer is ??. Each of them can change the weight by no more than 1

before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.

It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers’ weights in the team are different (i.e. unique).

Write a program that for given current values ​??

will find the maximum possible number of boxers in a team.

It is possible that after some change the weight of some boxer is 150001

(but no more).
Input

The first line contains an integer ?
(1≤?≤150000) — the number of boxers. The next line contains ? integers ?1,?2,…,??, where ?? (1≤??≤150000) is the weight of the ?

-th boxer.
Output

Print a single integer — the maximum possible number of people in a team.
Examples
Input
Copy

4
3 2 4 1

Output
Copy

4

Input
Copy

6
1 1 1 4 4 4

Output
Copy

5

Note

In the first example, boxers should not change their weights — you can just make a team out of all of them.

In the second example, one boxer with a weight of 1
can be increased by one (get the weight of 2), one boxer with a weight of 4 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 3 and 5, respectively). Thus, you can get a team consisting of boxers with weights of 5,4,3,2,1.

题意:给你一组数,你可以对一个数+1或者-1也可以不操作,问你可以生成几个不同的数字;

思路:直接贪心,想好优先级,尽量-1,然后是不变,最后是+1;

#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define ULL unsigned long long
using namespace std;
const int maxn=150000+10;
const int inf=0x3f3f3f3f;
int a[maxn];
int vis[maxn];
int main()
{int i,n,m,j,k,l;scanf("%d",&n);for(i=0;i<=n-1;i++){scanf("%d",&a[i]);}sort(a,a+n);int ans=0;for(i=0;i<=n-1;i++){if(a[i]-1>0&&vis[a[i]-1]==0){ans++;vis[a[i]-1]=1;}else if(a[i]>0&&vis[a[i]]==0){ans++;vis[a[i]]=1;}else if(vis[a[i]+1]==0){ans++;vis[a[i]+1]=1;}}printf("%d\n",ans);return 0;
}

codefrces 1203 E. Boxers(贪心)相关推荐

  1. codeforces 1203 E Boxers 贪心

    https://codeforces.com/problemset/problem/1203/E 题目大意:给 n n n个数,每个数可以做两种变化:(1) + 1 +1 +1:(2) − 1 -1 ...

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

    题目链接:https://codeforces.com/contest/1203/problem/E 思路:一开始想的是记录数字出现次数,看每个数字的三种变化能否产生新数,但是这样容易多算或者少算答案 ...

  3. Codeforces 1203E Boxers(贪心)

    题目链接:https://codeforces.com/problemset/problem/1203/E 题意:给定n个数字,每个数字可以进行一次+1或是-1的变换(也可以不变),问通过对部分数字适 ...

  4. E. Boxers(贪心)

    E. Boxers(贪心) There are nn boxers, the weight of the ii-th boxer is aiai. Each of them can change th ...

  5. URAL 1203 Scientific Conference(贪心 || DP)

    Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校,补多校的题目,刷一下一直薄弱的DP.多校如果有计算几何一定要干掉-.- 题意:给 ...

  6. Boxers CodeForces - 1203E (贪心解法)——26行代码AC

    立志用更少的代码做更高效的表达 There are n boxers, the weight of the i-th boxer is ai. Each of them can change the ...

  7. E. Boxers(贪心+移出多余空位)

    题意:给你n个数,然后你只能对一个数做一次操作使得这个数组里面的不同的数个数最多: 操作: 1.你可以对一个数-1(注意体重不能为0): 2.你可以对一个数+1: 3.你可以对这个数不做修改: 这道题 ...

  8. Codeforces Round #579 (Div. 3)--Boxers(贪心,排序)

    题目链接 题意: 给定n个质量为ai的盒子,每个盒子质量都可以改变不超过1的单位质量,求能够选出的互不相同的质量的盒子的最大数目. 题目条件: 1<=n<=150000,1<=ai& ...

  9. Codeforces Round #579 (Div. 3), problem: (E) Boxers【贪心】

    题目链接 题目大意 有n个拳击运动员,每个人在比赛前可以改变一斤体重,询问比赛时最多能带几个不同体重的运动员 题解 先排序,从大到小,优先先加一斤体重,再不变,最后考虑减一斤体重 #include&l ...

最新文章

  1. Linux镜像USB转网口驱动模块配置
  2. Nature:如何做一篇肠道菌群免疫的顶级文章
  3. Web Service之Soap请求响应内容中文编码解密
  4. MySQL federated 引擎跨服务器使用实例
  5. webpack的入口起点(EntryPoints)
  6. Kazuo Inamori
  7. C++ 动态二维数组(二维vector)
  8. [vue] 怎么使css样式只在当前组件中生效?
  9. 线上系统因为一个ThreadLocal直接内存飙升
  10. Redis 【string】 一句话说明
  11. oracle mysql认证考试流程_报考oraclemysql认证考试流程有些什么步骤
  12. msvcr71.dll缺失导致Oracle无法连接
  13. 2021年,中国程序员前景一片灰暗,真的是这样吗?
  14. pythonrq模块_Python RQ 任务队列中的队列 ( Queue )
  15. linux常用命令(2)关机重启 文本编辑器 系统管理 软件安装
  16. 最新wifi大师小程序独立版3.0.8源码
  17. stm32H70之使用片内的2Mflash
  18. 如何建立免费企业邮箱(腾讯、网易)
  19. Kafka(三):kafka消费者
  20. 好乐买总裁李树斌:10亿,突破技术瓶颈

热门文章

  1. ChatGPT可以作为一个翻译器吗?
  2. android 如何使用httpurlconnection下载一张图片demo
  3. 四旋翼无人机建模与实现(三)
  4. 谈一谈编程中的数学思维
  5. 系统管理员设置了系统策略禁止此安装怎么办
  6. 大卖家私域流量分享:从淘系私域到微信私域 品牌拓展私域流量的核心法则是…...
  7. Hadoop Single Node Setup(hadoop本地模式和伪分布式模式安装-官方文档翻译 2.7.3)
  8. xhr是什么缩写_微博上xhr和fsr是什么意思 饭圈里指黄新淳毕雯珺
  9. 基于php后台的购物商城微信小程序的设计与实现
  10. Python在Linux 目录的常用操作命令