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

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

  • 代码:

    int n;
    int tot[N];
    bool st[N]; int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,1,n){
    int x;
    cin>>x;
    tot[x]++;
    } int res=0; rep(i,1,150010){
    if(tot[i]==0) continue;
    if(i==1){
    if(tot[1]>=2){
    st[1]=true;
    st[2]=true;
    res+=2;
    }
    else if(tot[1]==1){
    st[1]=true;
    res++;
    }
    }
    else{
    if(tot[i]==1){
    if(!st[i-1]) {res++;st[i-1]=true;}
    else if(!st[i]) {res++;st[i]=true;}
    else if(!st[i+1]) {res++;st[i+1]=true;}
    }
    else if(tot[i]==2){
    int cnt=0;
    if(!st[i]) {res++;st[i]=true;cnt++;}
    if(!st[i-1]) {res++;st[i-1]=true;cnt++;}
    if(cnt==2) continue;
    if(!st[i+1]) {res++;st[i+1]=true;}
    }
    else{
    if(!st[i]) {res++;st[i]=true;}
    if(!st[i-1]) {res++;st[i-1]=true;}
    if(!st[i+1]) {res++;st[i+1]=true;}
    }
    }
    } cout<<res<<'\n';
    return 0;
    }

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. LeetCode 二分查找模板 III

    模板 #3: int binarySearch(vector<int>& nums, int target){ if (nums.size() == 0) return -1; i ...

  2. Docker 镜像管理及基础命令(二)

    Docker 常用命令: ## Docker 登录下载镜像: docker login # 登录官方hub.docker.com docker pull nginx:alpine # 下载nginx的 ...

  3. 从一次生产消费者的bug看看线程池如何增加线程

    0 背景 某个闲来无事的下午,看到旧有的项目中,有个任务调度的地方都是同步的操作,就是流程A的完成依赖流程B,流程B的完成依赖流程C,按此类推. 作为一名垃圾代码生产者,QA的噩梦.故障报告枪手的我来 ...

  4. Kubernetes K8S之kube-prometheus概述与部署

    Kubernetes K8S之kube-prometheus概述与部署 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master CentOS7. ...

  5. HATEOAS的简单认识

    HATEOAS: 超媒体作为应用程序状态引擎(HATEOAS)是REST应用程序体系结构的一个组件,它将其与其他网络应用程序体系结构区分开来. 使用HATEOAS,客户端与网络应用程序交互,其应用程序 ...

  6. 第2章_神经网络入门_2-5&2-6 数据处理与模型图构建

    目录 神经元的TF实现 安装 神经网络的TF实现 神经元的TF实现 安装 版本: Python 2.7 tf 1.8.0 Linux 略 demo 神经网络的TF实现 # py36 tf 2.1. # ...

  7. Ubuntu源、Python虚拟环境及pip源配置

    Ubuntu 命令行更改源 在修改source.list前,最好先备份一份 软件源的地址配置文件在 /etc/apt/sources.list 执行备份命令 sudo cp /etc/apt/sour ...

  8. Py基础—变量名,条件循环,空执行,编码,运算符,字符比较,简化写法

    变量名 只能是字母,数字,下划线.数字不能开头,不要和python内置的东西重复.赋予变量名内容:name1 = "shit" 输出变量名内容 print(name1) 条件语句 ...

  9. UDP flood UDP Port Denial-of-Service Attack

    https://baike.baidu.com/item/UDP%20flood/5504851 UDPFlood是日渐猖厥的流量型DoS攻击,原理也很简单.常见的情况是利用大量UDP小包冲击DNS服 ...

  10. python 使用函数名的字符串调用函数(4种方法)_black-heart的专栏-CSDN博客 https://blog.csdn.net/mrqingyu/article/details/84403924

    funcs = ['fetch_data_' + i for i in ( 'activities', 'banners', 'server_list')]# from operator import ...