• 题意:给你一组数,每个数都可以进行一次加一减一,问最后最多能有多少不同的数.

  • 题解:我们可以用桶存每个数的次数,然后枚举\([1,150001]\)来求对答案的贡献,然后贪心,这里我们不用担心其他乱七八糟的东西,直接根据桶中的个数来求贡献即可,但是要先选\(i-1\)的情况,因为后面的数取不到\(i-1\),假如我们不选\(i-1\),而是选了\(i\)和\(i+1\),后面的数可能会冲突不能选,而\(i\)和\(i+1\)就没必要考虑选择顺序了,因为无论他们和后面的数冲不冲突,对答案的贡献都是一样的.

  • 代码:

    1. int n;
    2. int tot[N];
    3. bool st[N];
    4. int main() {
    5. ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    6. cin>>n;
    7. rep(i,1,n){
    8. int x;
    9. cin>>x;
    10. tot[x]++;
    11. }
    12. int res=0;
    13. rep(i,1,150010){
    14. if(tot[i]==0) continue;
    15. if(i==1){
    16. if(tot[1]>=2){
    17. st[1]=true;
    18. st[2]=true;
    19. res+=2;
    20. }
    21. else if(tot[1]==1){
    22. st[1]=true;
    23. res++;
    24. }
    25. }
    26. else{
    27. if(tot[i]==1){
    28. if(!st[i-1]) {res++;st[i-1]=true;}
    29. else if(!st[i]) {res++;st[i]=true;}
    30. else if(!st[i+1]) {res++;st[i+1]=true;}
    31. }
    32. else if(tot[i]==2){
    33. int cnt=0;
    34. if(!st[i]) {res++;st[i]=true;cnt++;}
    35. if(!st[i-1]) {res++;st[i-1]=true;cnt++;}
    36. if(cnt==2) continue;
    37. if(!st[i+1]) {res++;st[i+1]=true;}
    38. }
    39. else{
    40. if(!st[i]) {res++;st[i]=true;}
    41. if(!st[i-1]) {res++;st[i-1]=true;}
    42. if(!st[i+1]) {res++;st[i+1]=true;}
    43. }
    44. }
    45. }
    46. cout<<res<<'\n';
    47. return 0;
    48. }

Codeforces Round #579 (Div. 3) E. Boxers (贪心)的更多相关文章

  1. Codeforces Round #579 (Div. 3)

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

  2. Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)

    http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 ...

  3. Codeforces Round #579 (Div. 3) D2. Remove the Substring (hard version) (思维,贪心)

    题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最 ...

  4. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

  5. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  6. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  7. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  8. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  9. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

随机推荐

  1. python基础学习总结

    python管理cisco设备:http://www.linuxeye.com/program/1680.html 学习:https://www.liaoxuefeng.com/wiki/001431 ...

  2. 剑指Offer-连续子数组中的最大和

    题目 输入一个整型数组,数组里有正数也有负数.数组中的一个或连续多个整数组成一个子数组.求所有子数组的和的最大值.要求时间复杂度为 O(n). 输入 [1,-2,3,10,-4,7,2,-5] 返回值 ...

  3. 面试官:Netty的线程模型可不只是主从多Reactor这么简单

    笔者看来Netty的内核主要包括如下图三个部分: 其各个核心模块主要的职责如下: 内存管理 主要提高高效的内存管理,包含内存分配,内存回收. 网通通道 复制网络通信,例如实现对NIO.OIO等底层JA ...

  4. 【Linux】用yum来下载rpm,而不安装

    方法一:yum yum命令本身就可以用来下载一个RPM包,标准的yum命令提供了--downloadonly(只下载)的选项来达到这个目的. $ sudo yum install --download ...

  5. Android之Xposed

    基础书籍推荐:1.疯狂JAVA讲义:2.疯狂安卓讲义: 逆向分析必须知道他的原理,不然只会用工具,那就直接GG. 谷歌的镜像网站:https://developers.google.com/andro ...

  6. Docker数据目录迁移解决方案

    场景 在docker的使用中随着下载镜像越来越多,构建镜像.运行容器越来越多, 数据目录必然会逐渐增大:当所有docker镜像.容器对磁盘的使用达到上限时,就需要对数据目录进行迁移. 如何避免: 1. ...

  7. Connection Pool

    MySQL :: MySQL Connector/NET Developer Guide :: 4.3 Managing a Connection Pool in Connector/NET http ...

  8. TCP/IP网络中的显式拥塞通告(ECN)

    当前的TCP 实现将TCP 端节点之间的中间网络视为一个不透明的"黑盒".TCP 包进入和流出这个盒子.有些时候进入盒子的包被丢失了.因为今天的数字和光媒体上出现比特级错误的机会非 ...

  9. WPF combobox设置默认选项不生效的问题

    combobox 是常用的控件,当我们需要绑定设置默认选项时,往往会绑定 SelectedItem 属性去设置, 可是你会惊奇地发现SelectedItem的值绑定了, 它依旧是熟悉的模样 根据官方的 ...

  10. 云原生项目实践DevOps(GitOps)+K8S+BPF+SRE,从0到1使用Golang开发生产级麻将游戏服务器—第1篇

    项目初探 项目地址: 原项目:https://github.com/lonng/nanoserver 调过的:https://github.com/Kirk-Wang/nanoserver 这将是一个 ...