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 ...
随机推荐
- listen 57
Secondhand Smoke Exposure Doubled Asthmatic Kids' Hospital Readmissions If your child has asthma哮喘, ...
- 「USACO15FEB」「LuoguP3121」审查(黄金)Censoring (Gold)(AC自动机
题目描述 Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they h ...
- poj1191棋盘分割——区间DP
题目:http://poj.org/problem?id=1191 分析题意,可知每次要沿棋盘中的一条线把一块一分为二,取其中一块继续分割: σ最小经分析可知即为每块的xi和的平方最小: 故用区间DP ...
- 逻辑回归(LogisticRegression)(未完)
部分引用: http://blog.csdn.net/pakko/article/details/37878837 http://blog.csdn.net/sunbow0/article/detai ...
- Python手动安装 package
https://pypi.python.org/pypi 下载 解压 进入setup.py的目录 python setup.py build python setup.py install
- POJ-2229
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 19599 Accepted: 7651 Descrip ...
- 来自word2013发布的测试文档
SWIG 是一个非常优秀的开源工具,支持您将 C/C++ 代码与任何主流脚本语言相集成. 此外,它向更广泛的受众公开了基本代码,改善了可测试性,让您的 Ruby 代码库某部分能快速写出高性能的 C/C ...
- ASP.NET Core会议管理平台实战_3、认证、授权表迁移
可以参考老张的这个文章: https://www.cnblogs.com/laozhang-is-phi/p/10660403.html 创建这个类库 看一下IdentityUser是在哪一个库下面. ...
- Spring入门第七课
Bean之间的关系:继承和依赖. 继承Bean配置 Spring允许继承bean的配置,被继承的bean称为父bean,继承这个父bean的Bean称为子Bean. 子Bean从父Bean中继承配置, ...
- BootStrap 概念
网格系统中的缩写; xs extra small sm smal md middle/medium lg large