链接:https://codeforces.com/contest/1173/problem/C

题意:

Nauuo is a girl who loves playing cards.

One day she was playing cards but found that the cards were mixed with some empty ones.

There are nn cards numbered from 11 to nn, and they were mixed with another nn empty cards. She piled up the 2n2n cards and drew nn of them. The nn cards in Nauuo's hands are given. The remaining nn cards in the pile are also given in the order from top to bottom.

In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile.

Nauuo wants to make the nn numbered cards piled up in increasing order (the ii-th card in the pile from top to bottom is the card ii) as quickly as possible. Can you tell her the minimum number of operations?

思路:

先考虑能不能直接出完。

再考虑出几个0之后,一起把n张牌出完。

假设第i张牌再第二个数组中的位置是pi,可以得到只有当其处在i-1这个位置时。才能一下n步出完。

得到res = max(res, pi-i+1+n).

代码:

#include <bits/stdc++.h>using namespace std;typedef long long LL;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;map<int, int> In;
int a[MAXN];int main()
{
//    freopen("test.in", "r", stdin);cin >> n;for (int i = 1;i <= n;i++)cin >> a[i], In[a[i]] = 0;for (int i = 1;i <= n;i++)cin >> a[i], In[a[i]] = i;if (In[1]){int i = 2;for (;In[i] == In[i-1]+1;i++);if(In[i-1] == n){int j;for (j = i;j <= n && In[j] <= j-i;j++);if (j > n){cout << n-i+1 << endl;return 0;}}}int res = 0;for (int i = 1;i <= n;i++)res = max(res, In[i]-i+1+n);cout << res << endl;return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10990891.html

Codeforces Round #564 (Div. 2) C. Nauuo and Cards相关推荐

  1. Codeforces Round #564 (Div. 2) A. Nauuo and Votes

    链接:https://codeforces.com/contest/1173/problem/A 题意: Nauuo is a girl who loves writing comments. One ...

  2. Codeforces Round #727 (Div. 2) E. Game with Cards dp + 思维

    传送门 文章目录 题意: 思路: 题意: 初始有左右手,上面各有一个数字为000的卡牌,每次都有一个新卡kik_iki​,你可以将其放在左手或者右手,使两只手上的卡片范围在[ll,i,rl,i][l_ ...

  3. Codeforces Round #564 (Div. 2)A

    A. Nauuo and Votes 题目链接:http://codeforces.com/contest/1173/problem/A 题目 Nauuo is a girl who loves wr ...

  4. Codeforces Round #712 (Div. 2) F. Flip the Cards 思维 + 贪心

    传送门 文章目录 题意: 思路: 题意: 给你nnn张卡片,每张卡片正面写有数字aaa,反面写有数字bbb,[1,2∗n][1,2*n][1,2∗n]之间的整数在这些数字中都恰好出现一次,我们认为这n ...

  5. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  6. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  7. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  8. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  9. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

最新文章

  1. Java基础-JAVA中常见的数据结构介绍
  2. 数据库9:联结表 高级联结 组合查询 全文本搜索
  3. #开发catia_CATIA工程制图二次开发之15:从平面创建剖面视图
  4. 音频编码解码器库 libZPlay
  5. 回头看看的时候openeim001
  6. python3.6.5下载安装教程_Ubuntu16.04安装python3.6.5步骤详解
  7. 比特币算法——SHA256算法介绍
  8. 基于modbus协议的工业自动化网络规范_一种基于Modbus的工业通信网关设计
  9. ucloud的弹性计算
  10. 推荐几款2021年好用的固定资产管理系统(软件)
  11. 微信公众平台接入广告投放系统
  12. Ubuntu 启动图标变成问号
  13. Java基础梳理第二天03(继承、抽象类、多态)
  14. 84. 从视图索引说Notes数据库(下)
  15. 评郭德纲《论50年相声之现状》
  16. 斜杠'/' 和反斜杠'\'
  17. ucos 时钟节拍_uC/OS-III 时钟节拍,时间管理,时间片调度
  18. php开发API接口的代码案例
  19. wpe解密系列001
  20. Linux升级gcc到最新版本--gcc-9.1.0

热门文章

  1. html内置时间对象,JavaScript中的常用事件,以及内置对象详解
  2. oracle批量替换保留字,oracle保留字大全
  3. php学习总结,PHP学习的技巧和学习的要素总结
  4. es6新特性之Map
  5. SecureCRT打开文件中文乱码
  6. Ajax--同源策略,jsonp跨域传输原理(callback),
  7. kafka介绍和集群环境搭建
  8. 移动设备的界面设计尺寸
  9. 软件设计中架构和框架的区别
  10. 这段js代码得拯救你多少时间