传送门 https://codeforces.com/contest/1496/problem/B

 

题目

Example
input
5
4 1
0 1 3 4
3 1
0 1 4
3 0
0 1 4
3 2
0 1 2
3 2
1 2 3
output
4
4
3
5
3
Note

In the first test case, S={0,1,3,4}S={0,1,3,4}, a=mex(S)=2a=mex⁡(S)=2, b=max(S)=4b=max(S)=4, ⌈a+b2⌉=3⌈a+b2⌉=3. So 33 is added into SS, and SS becomes {0,1,3,3,4}{0,1,3,3,4}. The answer is 44.

In the second test case, S={0,1,4}S={0,1,4}, a=mex(S)=2a=mex⁡(S)=2, b=max(S)=4b=max(S)=4, ⌈a+b2⌉=3⌈a+b2⌉=3. So 33 is added into SS, and SS becomes {0,1,3,4}{0,1,3,4}. The answer is 44.

前言(写给自己的话)

最近cf做得越来越不好了,  出了A后, B就不怎么出了, 这样不行啊, 说是晚上困, 那困之前怎么不出B题? 这道题就是简单的模拟, 只有三种情况, 不应该不出, 往思维上想, 思维! 思维!


英语__硬伤
      rounded up--------四舍五入  7.5 = 8;
Output

For each test case, print the number of distinct elements in S after k operations will be done.       输出有几种数, 我理解成输出出现一次的数的个数了  

解析

先对数组排序,求出mex。如果操作后得到的数在数列出现过,
那么直接输出n(因为再操作也还是得到这个数),如果没在
数列出现过则输出n + 1,因为这并不会改变mex和max,再操
作还是得到这个数。如果原数列已经被填满,即mex == n,
那么就输出n + k(可以自己模拟一下)。

三种情况:

1. mex==n, 也就是说0~n-1都有, 那么每次把d=(mex + max + 1)/2加入进去, 不重合的数就+1, 重复加k次

2. 所求d在n个数里出现过, 那输出n

3. 所求d在n个数里没出现过, 那输出n+1, 因为再怎么进行, 得到的都是这一个数


代码

#include <iostream>
#include <algorithm> using namespace std; const int N = 1e5 + 10; int a[N], n ; bool find(int x)
{
for(int i = 0; i < n; i ++)
if(a[i ] == x)
return 1;
return 0;
} int main()
{
int t;
cin >> t; while(t --)
{
int k;
cin >> n >> k; int maxn = 0, mex = n;
for(int i = 0; i < n; i ++)//最大值永远是最大值
{
scanf("%d", &a[i]);
maxn = max(maxn, a[i]);
}
sort(a, n + a);
for(int i = 0; i < n; i ++)//排序后找mex
if(i != a[i] && mex == n)
mex = i; if( k == 0 || find((maxn + mex + 1) / 2))
printf("%d\n", n);
else if(mex == n)
printf("%d\n", n + k);
else
printf("%d\n", n+1);
} return 0;
}

Codeforces Round #706 (Div. 2)B. Max and Mex __ 思维, 模拟的更多相关文章

  1. Codeforces Round #416 (Div. 2) A. Vladik and Courtesy【思维/模拟】

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. Codeforces Round #614 (Div. 1) A. NEKO's Maze Game (思维,模拟)

    题意:有一个\(2\)X\(n\)的矩阵,你想从\((1,1)\)走到\((2,n)\),每次可以向上下左右四个方向走,但在某些时间段某个点会被堵住,如果已经被堵住,那么即恢复正常,每次对某个点操作, ...

  3. Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维,模拟栈)

    题意:给你一串括号,每次仅可以修改一个位置,问有多少位置仅修改一次后所有括号合法. 题解:我们用栈来将这串括号进行匹配,每成功匹配一对就将它们消去,因为题目要求仅修改一处使得所有括号合法,所以栈中最后 ...

  4. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  5. Codeforces Round #330 (Div. 2)D. Max and Bike 二分 物理

    D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/probl ...

  6. Codeforces Round #330 (Div. 2) D. Max and Bike 二分

    D. Max and Bike For months Maxim has been coming to work on his favorite bicycle. And quite recently ...

  7. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  8. Codeforces Round #379 (Div. 2) A B C D 水 二分 模拟

    A. Anton and Danik time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

随机推荐

  1. 后门及持久化访问2----进程注入之AppCertDlls 注册表项

    代码及原理介绍 如果有进程使用了CreateProcess.CreateProcessAsUser.CreateProcessWithLoginW.CreateProcessWithTokenW或Wi ...

  2. 开源三轴云台EVVGC(simple BGC)分析

    一. 主程序分析 主程序结构清晰,流程如图所示,下面将对每个部分做详细分析 二. 系统初始化 系统初始化部分的流程如上图所示,下面对每部分做具体分析 1. 时钟初始化 该部分主要是使能DWT,用DWT ...

  3. MySQL—索引(Index)

    前言: 关于MySql索引数据结构和实现原理的讲解值得阅读一下: 实现原理:https://www.cnblogs.com/songwenjie/p/9415016.htm 索引数据结构:https: ...

  4. [Java编程思想] 第七章 复用类

    第七章 复用类 第一种方法非常直观:只需在新的类中产生现有类的对象(组合). 第二种方法更细致一些:它按照现有类的类型来创建新类(继承). 7.1 组合语法   只需将对象引用置于新类中即可. cla ...

  5. (数据科学学习手札135)tenacity:Python中最强大的错误重试库

    本文示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 我们在编写程序尤其是与网络请求相关的程序, ...

  6. 一台 Linux 系统初始化环境后需要做一些什么安全工作?

    1.添加普通用户登陆,禁止 root 用户登陆,更改 SSH 端口号.        修改 SSH 端口不一定绝对哈.当然,如果要暴露在外网,建议改下.l    2.服务器使用密钥登陆,禁止密码登陆. ...

  7. docker安装部署、fastDFS文件服务器搭建与springboot项目接口

    一.docker安装部署 1.更新yum包:sudo yum update 2.安装需要的软件包,yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动 ...

  8. 一个 Spring 的应用看起来象什么?

    一个定义了一些功能的接口.这实现包括属性,它的 Setter , getter 方法和函数等.Spring AOP.Spring 的 XML 配置文件.使用以上功能的客户端程序.

  9. isNotEmpty 与 isNotBlank 的区别

    isNotEmpty(str)等价于 str != null && str.length > 0 isNotBlank(str) 等价于 str != null &&am ...

  10. 打败算法 —— 环形链表 II

    本文参考 出自LeetCode上的题库 -- 环形链表II,哈希表和快慢指针两种解法都需要O(n)的时间,但快慢指针仅占用O(1)的空间 https://leetcode-cn.com/problem ...