题意:

给[1,n]的两个排列,统计有多少个二元组(a,b)满足a是A的连续子序列,b是B的连续子序列,a,b中包含的数相同;

思路:

由于是连续的序列,且长度相同,可以枚举一个串的子串,找出这个子串在另一个串的最小位置和最大位置,看之间相距的长度是否是子串的长度;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e7+10;
const int maxn=3e3+10;
const double eps=1e-6; int n;
int b[maxn],l[maxn][maxn],r[maxn][maxn],p[maxn];
int main()
{
while(1)
{
read(n);
if(n==0)break;
int a;
For(i,1,n)read(a),p[a]=i;
For(i,1,n)read(b[i]);
int ans=0;
For(i,1,n)
{
l[i][i]=r[i][i]=p[b[i]];
For(j,i+1,n)
{
l[i][j]=min(l[i][j-1],p[b[j]]);
r[i][j]=max(r[i][j-1],p[b[j]]);
if(r[i][j]-l[i][j]==j-i)ans++;
}
}
cout<<ans<<"\n";
} return 0;
}

  

LA-5052 (暴力)的更多相关文章

  1. HDU 5745 La Vie en rose 暴力

    La Vie en rose 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5745 Description Professor Zhang woul ...

  2. LA 3602 DNA Consensus String (暴力枚举)

    题意:给定m个长度为n的DNA序列,求一个最短的DNA序列,使得总Hamming距离最小. Hamming距离等于字符不同的位置个数. 析:看到这个题,我的第一感觉是算时间复杂度,好小,没事,完全可以 ...

  3. LA 6621 /ZOJ 3736 Pocket Cube 打表+暴力

    这道题是长沙区域赛的一道简单题,当时题目在ZOJ重现的时候就做了一次,但是做的好复杂,用的BFS暴力,而且还没打表,最后还是莫名其妙的爆栈错误,所以就一直没弄出来,昨天做到大白书上例题05年东京区域赛 ...

  4. Java实现 蓝桥杯 算法训练 Remember the A La Mode(暴力)

    试题 算法训练 Remember the A La Mode 问题描述 Hugh Samston经营着一个为今年的ICPC世界总决赛的参与者提供甜点的餐饮服务.他将会提供上面有冰激凌的饼片.为了满足不 ...

  5. LA 7263 Today Is a Rainy Day bfs+暴力 银牌题

    7263 Today Is a Rainy Day Today is a rainy day. The temperature is apparently lower than yesterday. ...

  6. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  7. Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. bzoj 3620 暴力KMP

    十分暴力的KMP,枚举左端点,在向右侧推进的同时,取较小的la保证条件,n方暴力 #include<bits/stdc++.h> #define rep(i,j,k) for(int i= ...

  9. bzoj 3916 暴力哈希

    暴力的哈希,注意: 将一个串当作另一个串的前缀,需要乘上p[len],len=后面串的长度 这是自己的代码,拿数据在本地测A掉了,但是bz上wa了??bz换数据了难道?? #include<cs ...

  10. hdu2087 剪花布条 暴力/KMP

    在字符串中不可重叠地寻找子串数量,暴力/KMP #include<stdio.h> #include<string.h> int main(){ ],b[]; ]!='#'){ ...

随机推荐

  1. 在dedecms系统下, 改写火车头的入库接口 写一个接口文件运行一次自动读取 http://news.163.com/rank/

    1:火车头入库接口里面的密码与login.php传过来的密码是保持一致的: 2:在(!$ispost)里面编写一个form表单提交,验证用户名,channelid,以及typeid; html代码格式 ...

  2. docker-nginx-标记一下

    拉取nginx镜像 然后启动容器: docker run -p : --name mynginx -d -v $PWD/nginx.conf:/etc/nginx/conf.d/default.con ...

  3. input标签附带提示文字(bootstrap里面输入框的两侧同时添加额外元素)

    一直不太喜欢用定位,今天写界面的时候,要在输入框右边添加默认的元素符号. 第一次尝试,因为本身项目用的是bootstrap所以就想利用输入框的两侧同时添加额外元素. 但是写了代码发现效果不同. 第二次 ...

  4. Codeforces 540 D Bad Luck Island

    Discription The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp pap ...

  5. hadoop学习 的yarn

    Yarn的产生 mapReduc1.0 1单点故障 2扩展效率低 3资源利用率高 降低运维成本 方便数据共享 多计算框架支持 MapReduce Spark Storm Yarn的架构图 Yarn模块 ...

  6. CSS 居中 可随着浏览器变大变小而居中

    关键代码: 外部DIV使用: text-align:center; 内部DIV使用: margin-left:auto;margin-right:auto 例: <div style=" ...

  7. react 起手式

    http://blog.csdn.net/zhouzhiande/article/details/52349344 http://blog.csdn.net/zhouzhiande/article/d ...

  8. 【paddle学习】词向量

    http://spaces.ac.cn/archives/4122/   关于词向量讲的很好 上边的形式表明,这是一个以2x6的one hot矩阵的为输入.中间层节点数为3的全连接神经网络层,但你看右 ...

  9. [转]Linux统计代码行数

    wc -l *.c *.h 就可以知道当前目录下的所有c 和 h 文件的行数的详细信息.很不错 如果要递归,可以配合其他命令一起使用 当前目录及子目录: find . -name *.c |xargs ...

  10. Django简易安装

    Django简易安装 1,下载 https://www.djangoproject.com/download/ 2, 拷贝至python同级目录 python setup.py install 3,在 ...