Codeforces Round #706 (Div. 2)B. Max and Mex __ 思维, 模拟
传送门 https://codeforces.com/contest/1496/problem/B
题目
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
4
4
3
5
3
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题? 这道题就是简单的模拟, 只有三种情况, 不应该不出, 往思维上想, 思维! 思维!

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 __ 思维, 模拟的更多相关文章
- 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 ...
- Codeforces Round #614 (Div. 1) A. NEKO's Maze Game (思维,模拟)
题意:有一个\(2\)X\(n\)的矩阵,你想从\((1,1)\)走到\((2,n)\),每次可以向上下左右四个方向走,但在某些时间段某个点会被堵住,如果已经被堵住,那么即恢复正常,每次对某个点操作, ...
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维,模拟栈)
题意:给你一串括号,每次仅可以修改一个位置,问有多少位置仅修改一次后所有括号合法. 题解:我们用栈来将这串括号进行匹配,每成功匹配一对就将它们消去,因为题目要求仅修改一处使得所有括号合法,所以栈中最后 ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 【ASP.NET Core】MVC模型绑定——实现同一个API方法兼容JSON和Form-data输入
在上一篇文章中,老周给大伙伴们大致说了下 MVC 下的模型绑定,今天咱们进行一下细化,先聊聊模型绑定中涉及到的一些组件对象. ------------------------------------- ...
- IC设计学习路线
一 前言 一直以来都是这也想学那也想学,搞个两三个月又放弃了,开始搞新的,从来没有任何东西超过一年,更不要说坚持三年.现在经历的事情多了,学过各种编程语言明白了要想学会一个专业技能,至少是三年.得到软 ...
- SINAMICS S120的核心控制单元CU320使用教程,电机模块接线
SINAMICS是西门子公司新一代的驱动产品,它正在逐步取代现有的MASTERDRIVES及SIMODRIVE系列的驱动系统.SINAMICS S120是集V/f控制.矢量控制和伺服控制于一体的多轴驱 ...
- Vue中import和require的对比
Vue中import和require的对比 一.前言 vue框架想必是我们前端朋友们必学的知识点,说它难也没有那么难,说简单也没有那么简单,主要技术就是那么几个,可是里面的细节很多,有些时候我们会 ...
- java高级用法之:调用本地方法的利器JNA
目录 简介 JNA初探 JNA加载native lib的流程 本地方法中的结构体参数 总结 简介 JAVA是可以调用本地方法的,官方提供的调用方式叫做JNI,全称叫做java native inter ...
- vue单文件组件data选项的函数体获取vue实例对象
因配置的关系,导致 vue的data选项中存在事件.而事件无法获取 vue 的实例对象:项目是单文件形式的,以下代码只是例子 new Vue({ el:..., data:{ a: { onevent ...
- spring-boot -缓存注解
缓存:商品信息放到缓存中间件中, 验证码几秒钟有效也是放在缓存中间件. 缓存规范 交互流程: 如果需要使用jRS107需要导入包: java.cache.cache-api JSR107提供的是接口, ...
- 复杂JSON字符串解析,可以少走弯路
发现一个好文章:装载至http://www.verejava.com/?id=17174254038220 package com.json5; import org.json.JSONArra ...
- 插值方法 - Lagrange插值多项式
Lagrange插值多项式代码: 1 # -*- coding: utf-8 -*- 2 """ 3 Created on Wed Mar 25 15:43:42 202 ...
- docker 容器简单使用
文章目录 docker简介 docker容器简单使用 1.HelloWorld 2.运行交互式的容器 3.启动容器(后台模式) 安装docker容器的博文有很多这里就不做过多赘述了,另外如果不想安装d ...