链接: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;
}

  

Codeforces Round #564 (Div. 2) C. Nauuo and Cards的更多相关文章

  1. Codeforces Round #564 (Div. 2) B. Nauuo and Chess

    链接:https://codeforces.com/contest/1173/problem/B 题意: Nauuo is a girl who loves playing chess. One da ...

  2. 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 ...

  3. Codeforces Round #564 (Div. 2) D. Nauuo and Circle(树形DP)

    D. Nauuo and Circle •参考资料 [1]:https://www.cnblogs.com/wyxdrqc/p/10990378.html •题意 给出你一个包含 n 个点的树,这 n ...

  4. Codeforces Round #564 (Div. 1)

    Codeforces Round #564 (Div. 1) A Nauuo and Cards 首先如果牌库中最后的牌是\(1,2,\cdots, k\),那么就模拟一下能不能每次打出第\(k+i\ ...

  5. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

  6. Codeforces Round #564 (Div. 2)

    传送门 参考资料 [1]: the Chinese Editoria A. Nauuo and Votes •题意 x个人投赞同票,y人投反对票,z人不确定: 这 z 个人由你来决定是投赞同票还是反对 ...

  7. Codeforces Round #564 (Div. 2)B

    B. Nauuo and Chess 题目链接:http://codeforces.com/contest/1173/problem/B 题目 Nauuo is a girl who loves pl ...

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

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

  9. Codeforces Round #384 (Div. 2) E. Vladik and cards 状压dp

    E. Vladik and cards 题目链接 http://codeforces.com/contest/743/problem/E 题面 Vladik was bored on his way ...

随机推荐

  1. HTML5响应式模版Mocha

    HTML5响应式模版Mocha,经典,html5,蓝色,扁平,HTML5响应式模版Mocha是一款宽屏大气的HTML5网站展示模板. http://www.huiyi8.com/moban/

  2. JS工具函数汇总

    备注:http://phpjs.org/  这个站点把PHP常用的方法用js实现了,推荐一下 1.从数组中随机获取几个不重复项 //从一个给定的数组arr中,随机返回num个不重复项 function ...

  3. Facebook的实时流处理技术——Scuba是Facebook的一个非常快速、分布式的内存数据库,用于实时分析和查询

    Scuba,Facebook的一个非常快速.分布式的内存数据库,用于实时分析和查询.是Facebook的回归分析代码.错误报告监控.广告收入监控和性能调试的背后主力. Facebook的实时流处理技术 ...

  4. Linux_异常_03_Failed to restart iptables.service: Unit not found.

    启动防火墙时出现: Failed to restart iptables.service: Unit not found. 解决方案: 1.https://stackoverflow.com/ques ...

  5. 勤于思考:IE10不支持检测IE6的代码

    这句话 var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6); 在IE6~9都没问题 ...

  6. 「LuoguP1144」 最短路计数(dijkstra

    题目描述 给出一个NN个顶点MM条边的无向无权图,顶点编号为1-N1−N.问从顶点11开始,到其他每个点的最短路有几条. 输入输出格式 输入格式: 第一行包含22个正整数N,MN,M,为图的顶点数与边 ...

  7. docker学习 (二)基本概念

    基本概念: Docker包括三个基本概念: 镜像(Image): 特殊的文件系统,提供容器运行时所需的程序.库.资源.配置文件.镜像不包含动态数据,内容在构建后不会被改变. 容器(Container) ...

  8. 在浏览器端用JS创建和下载文件

    前端很多项目中,都有文件下载的需求,特别是JS生成文件内容,然后让浏览器执行下载操作(例如在线图片编辑.在线代码编辑.iPresst等). 但受限于浏览器,很多情况下我们都只能给出个链接,让用户点击打 ...

  9. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

  10. 异步和多线程,委托异步调用,Thread,ThreadPool,Task,Parallel,CancellationTokenSource

    1 进程-线程-多线程,同步和异步2 异步使用和回调3 异步参数4 异步等待5 异步返回值 5 多线程的特点:不卡主线程.速度快.无序性7 thread:线程等待,回调,前台线程/后台线程, 8 th ...