要点

  • 没想到的一点是,对于堆里的某牌,最好情况是它出来时后边都准备就绪了,答案是\(p[i] + (n - i + 1)\),所有的这个取最大的即可
  • 一发结束的情况先特判一下
const int maxn = 2e5 + 5;
int n, pos, ans;
int a[maxn], b[maxn], In[maxn], p[maxn]; int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n) {
cin >> a[i];
}
rep(i, 1, n) {//in pile
cin >> b[i];
if (b[i] == 1) pos = i;
}
if (pos) {//special
int flag = 1, k = 1;
rep(i, pos, n)//1 2 3......until the end
if (b[i] != k++) {
flag = 0; break;
}
if (flag) {
rep(i, 1, n)//in hand
In[a[i]] = 1;
int need = n - pos + 2;
rep(i, 1, pos - 1) {
if (!In[need]) {
flag = 0; break;
}
In[b[i]] = 1;
need++;
}
if (flag) {//一气呵成
cout << pos - 1 << endl;
exit(0);
}
}
} rep(i, 1, n)
p[b[i]] = i;
rep(i, 1, n)
ans = max(ans, p[i] + (n - i + 1));//all ready for those behind i
cout << ans << endl;
return 0;
}

Codeforces #564div2 C(模拟)的更多相关文章

  1. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  2. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  3. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  4. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  5. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  6. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

  7. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑...

  8. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

  9. CodeForces 697B Barnicle 模拟

    强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...

随机推荐

  1. 时尚设计div+css免费模板

    时尚设计div+css免费网页模板,时尚设计,div+css. http://www.huiyi8.com/moban/

  2. 夏日户外风景PSD素材

    夏日户外风景PSD素材适用于向日葵素材背景图设计 地址:http://www.huiyi8.com/xiangrikui/​

  3. linux 下errno各个值的意义(转) errno.h

    strerror(errno):获取errno对应的错误 查看错误代码errno是调试程序的一个重要方法.当linux C api函数发生异常时,一般会将errno变量(需include errno. ...

  4. darknet YOLOv2安装及数据集训练

    一. YOLOv2安装使用 1. darknet YOLOv2安装 git clone https://github.com/pjreddie/darknetcd darknetmake或到网址上下载 ...

  5. CRC16算法之一:CRC16-CCITT-FALSE算法的java实现

    CRC16算法系列文章: CRC16算法之一:CRC16-CCITT-FALSE算法的java实现 CRC16算法之二:CRC16-CCITT-XMODEM算法的java实现 CRC16算法之三:CR ...

  6. python爬虫知识点总结(二)爬虫的基本原理

    一.什么是爬虫? 答:请求网页并提取数据的自动化程序. 二.爬虫的基本流程 三.什么是Request和Response? 1.Request 2.Response 四.能抓取怎样的数据 五.解析方式 ...

  7. 乱写的一个SQL框架

    闲来没事,看了mybatis的实现形式,就心血来潮的自己弄了一个仿照mybatis的框架,性能肯定不好,而且有很多问题,但是是一次有益的尝试 1.基本配置文件 <!--加载数据源--> & ...

  8. MyEclipse修改Servlet模板

    进入myeclipse的安装路径 然后进入plugins文件夹 打开搜索框,输入 *wizard* 找到名字是 com.genuitec.eclipse.wizards_11.5.0.me201310 ...

  9. ng2中router-outlet用法

    说明:router-outlet 是应用中的路由插座,一个页面中可以使用一个或多个router-outlet 1.只使用一个router-outlet 父组件: <router-outlet&g ...

  10. python的logging模块详细使用demo

    import logging import os from logging import handlers from datetime import datetime class MyLog(): d ...