[BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II
Description
Input
Output
Sample Input
1
2
3
4
5
6
6
5
4
3
2
1
Sample Output
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define reg register
inline char gc() {
static const int bs = << ;
static unsigned char buf[bs], *st, *ed;
if (st == ed) ed = buf + fread(st = buf, , bs, stdin);
return st == ed ? EOF : *st++;
}
#define gc getchar
inline int read() {
int res=;char ch=gc();bool fu=;
while(!isdigit(ch))fu|=(ch=='-'), ch=gc();
while(isdigit(ch))res=(res<<)+(res<<)+(ch^), ch=gc();
return fu?-res:res;
}
#define N 100005
int n;
int a[N], b[N];
int pos[N];
int c[N*], cnt, tmp[];
int low[N*], ans; int main()
{
n = read();
for (reg int i = ; i <= n ; i ++) a[i] = read();
for (reg int i = ; i <= n ; i ++) pos[b[i] = read()] = i;
for (reg int i = ; i <= n ; i ++)
{
int top = ;
for (reg int j = max(, a[i] - ) ; j <= min(n, a[i] + ) ; j ++)
tmp[++top] = pos[j];
sort(tmp + , tmp + + top);
for (reg int j = top ; j >= ; j --) c[++cnt] = tmp[j];
}
low[++ans] = c[];
for (reg int i = ; i <= cnt ; i ++)
{
if (c[i] > low[ans]) low[++ans] = c[i];
else {
int t = lower_bound(low + , low + + ans, c[i]) - low;
low[t] = c[i];
}
}
cout << ans << endl;
return ;
}
[BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II的更多相关文章
- [BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II dp
4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II Time Limit: 10 Sec Memory Limit: 128 MBSubmi ...
- BZOJ4990 [Usaco2017 Feb]Why Did the Cow Cross the Road II 动态规划 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4990 题意概括 有上下两行长度为 n 的数字序列 A 和序列 B,都是 1 到 n 的排列,若 a ...
- 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 线段树维护dp
题目 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 链接 http://www.lydsy.com/JudgeOnline/proble ...
- BZOJ4993 [Usaco2017 Feb]Why Did the Cow Cross the Road II 动态规划 树状数组
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ4993 题意概括 有上下两行长度为 n 的数字序列 A 和序列 B,都是 1 到 n 的排列,若 a ...
- [BZOJ4993||4990] [Usaco2017 Feb]Why Did the Cow Cross the Road II(DP + 线段树)
传送门 f[i][j]表示当前第i个,且最后一个位置连接到j 第一维可以省去,能连边的点可以预处理出来,dp可以用线段树优化 #include <cstdio> #include < ...
- [Usaco2017 Feb]Why Did the Cow Cross the Road II (Platinum)
Description Farmer John is continuing to ponder the issue of cows crossing the road through his farm ...
- [Usaco2017 Feb]Why Did the Cow Cross the Road II (Gold)
Description 上下有两个长度为n.位置对应的序列A.B, 其中数的范围均为1~n.若abs(A[i]-B[j])<= 4,则A[i]与B[j]间可以连一条边. 现要求在边与边不相交的情 ...
- 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
题面:4989: [Usaco2017 Feb]Why Did the Cow Cross the Road 连接 http://www.lydsy.com/JudgeOnline/problem.p ...
- [BZOJ4989][Usaco2017 Feb]Why Did the Cow Cross the Road 树状数组维护逆序对
4989: [Usaco2017 Feb]Why Did the Cow Cross the Road Time Limit: 10 Sec Memory Limit: 256 MBSubmit: ...
随机推荐
- JavaScript和JQuery进行页面跳转
1.JavaScript页面跳转 .我们可以利用http的重定向来跳转 window.location.replace("网址"); .使用href来跳转 window.locat ...
- Hive的动态分区
关系型数据库(如Oracle)中,对分区表Insert数据时候,数据库自动会根据分区字段的值,将数据插入到相应的分区中,Hive中也提供了类似的机制,即动态分区(Dynamic Partition), ...
- 【学习笔记】第一章 python安全开发简介
1.1为什么黑客喜欢用python? python为我们提供了非常完善的基础代码库,覆盖了网络.文件.GUI.数据库.文本等大量内容,被形象的称为“”内置电池“”,用python开发,许多功能不必从零 ...
- 开源导入导出通用库Magicodes.ExporterAndImporter发布
导入导出通用库 Magicodes.ExporterAndImporter为心莱团队封装的导入导出通用库,并且仍在跟随项目不断地打磨. GitHub地址: https://github.com/xin ...
- CentOS 7.6安装MySQL 5.7GA版
环境准备 卸载mariadb rpm -qa | grep mariadb rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 centos7 内部集 ...
- spring aop介绍和示例
参考:<Spring in Action> 一.AOP介绍 AOP是Aspect Oriented Programming的缩写,意思是面向切面编程. 应用中有一些功能使用非常普遍,比如事 ...
- Basler acA2500-14gm 连接采图报错处理
新购 Basler acA2500-14gm 相机,使用从官方网站下载的 pylon v6 版本连接测试,报错: Type Time Source MessageError 2 ...
- lcx端口转发
目录 0x01 正向端口转发 0x02 反向端口转发 0x03 msf正向shell 0x04 msf反向shell 注: 边界机器 win08 192.168.222.175 内网机器 win7 1 ...
- 素数路径Prime Path POJ-3126 素数,BFS
题目链接:Prime Path 题目大意 从一个四位素数m开始,每次只允许变动一位数字使其变成另一个四位素数.求最终把m变成n所需的最少次数. 思路 BFS.搜索的时候,最低位为0,2,4,6,8可以 ...
- CF #579 (Div. 3) A.Circle of Students
A. Circle of Students time limit per test2 seconds memory limit per test256 megabytes inputstandard ...