Codeforces #564div2 C(模拟)
要点
- 没想到的一点是,对于堆里的某牌,最好情况是它出来时后边都准备就绪了,答案是\(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(模拟)的更多相关文章
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces 679B. Barnicle 模拟
B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...
- CodeForces 382C【模拟】
活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...
- codeforces 719C (复杂模拟-四舍五入-贪心)
题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑...
- CodeForces 705C Thor (模拟+STL)
题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...
- CodeForces 697B Barnicle 模拟
强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...
随机推荐
- 使用C++模拟C#的委托机制
1. [代码][C/C++]代码 //Event.h #ifndef _EVENT_H_#define _EVENT_H_class EmptyObject {};template<typen ...
- Android 7.1 GUI系统-窗口管理WMS-Surface管理(四)
Surface的管理 Surface是窗口能真正显示到物理屏幕上的基础,由surfaceflinger管理,可以通过WindowStateAnimator.java中的变量mDrawState来查看每 ...
- LNMP安装(二)
PHP安装 1.yum安装一些依赖库 yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel ...
- linux 进程学习笔记-共享内存
如果能划定一块物理内存,让多个进程都能将该内存映射到其自身虚拟内存空间的话,那么进程可以通过向这块内存空间读写数据而达到通信的目的.另外,和消息队列不同的是,共享的内存在用户空间而不是核空间,那么就不 ...
- ACM学习历程—SNNUOJ 1116 A Simple Problem(递推 && 逆元 && 组合数学 && 快速幂)(2015陕西省大学生程序设计竞赛K题)
Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N- ...
- 【Lintcode】094.Binary Tree Maximum Path Sum
题目: Given a binary tree, find the maximum path sum. The path may start and end at any node in the tr ...
- linux下Redis以及c++操作
使用不同的语言,redis支持不同的编程语言,但是调用了不同的redis包,例如: java对应jedis: php对应phpredis: C++对应的则是hredis. 安装Redis 上篇博客已经 ...
- 网络最大流dinic模板
#include<iostream> #include<cstdio> #include<cstring> #include<queue> using ...
- 洛谷P1080(NOIP2012)国王游戏——贪心排序与高精度
题目:https://www.luogu.org/problemnew/show/P1080 排序方法的确定,只需任取两个人,通过比较与推导,可以得出ai*bi小的人排在前面: 高精度写的时候犯了些细 ...
- Ubuntu ssh免密登录
ssh免密登录工作原理 server A免登录到server B: 1.在A上生成公钥私钥. 2.将公钥拷贝给server B,要重命名成authorized_keys(从英文名就知道含义了) 3.S ...