传送门 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. 变频器通讯参数PKW和PZD的含义

    SINAMICS S120 S150 参数手册 章节3.9 PROFIdrive 图3-41 功能图2422制造商专用报文和过程数据 参考:https://www.diangon.com/wenku/ ...

  2. [AT2306]Rearranging(拓扑序)

    [AT2306]Rearranging(拓扑序) 只有luogu 题面(luogu): 有一个$n$个数组成的序列$a_{i}$. 高桥君会把整个序列任意排列,然后青木君可以选择两个相邻的互质的数交换 ...

  3. zookeeper的通知机制

    一.znode Zookeeper维护一个类似文件系统的数据结构.简单来说,有点类似windows中注册表的结构,有名称,有树节点,有Key(键)/Value(值)对的关系,可以看做一个树形结构的数据 ...

  4. springboot的核心配置文件

    一.springboot主要配置文件种类 1.bootstrap (.yml或.properties) 2.application(.yml或.properties) 二.bootstrap与appl ...

  5. python django对数据表的增删改查操作

    新增操作:方式1:book = BookInfo(title='西游记',price=99)book.save() 方式2:BookInfo.objects.create(title='西游记',pr ...

  6. Hibernate实体的三种状态是什么?各有什么特点?

    瞬时态(Transient). 持久态(Persistent).脱管态(Detached).处于持久态的对象也称为PO(Persistence Object),瞬时对象和脱管对象也称为VO(Value ...

  7. 什么是 WebSockets?

    WebSocket 是一种计算机通信协议,通过单个 TCP 连接提供全双工通信信道. 1.WebSocket 是双向的 -使用 WebSocket 客户端或服务器可以发起消息发送. 2.WebSock ...

  8. springBoot 多配置文件切换之profile

    说明: 我们平时工作,有开发环境,和生产环境,利用springboot的多profile配置,可以很轻松切换配置. 实现方式1(推荐): 配置文件命名遵循:application-{开发模式}.pro ...

  9. SpringDataRedis的Keyspaces设置

    前言 原文:https://docs.spring.io/spring-data/redis/docs/2.3.2.RELEASE/reference/html/#redis.repositories ...

  10. Java 中 WeakReference 与 SoftReference 的区别?

    虽然 WeakReference 与 SoftReference 都有利于提高 GC 和 内存的效率, 但是 WeakReference ,一旦失去最后一个强引用,就会被 GC 回收,而软引用 虽然不 ...