CodeForces 187A Permutations
反向思维,先求数组中不用处理的元素个数,再用n减去这个数,得到结果。
#include <iostream>
#include <cstring> #define maxn 200000+10 using namespace std; int n;
int a[maxn],b[maxn];
int visit[maxn];
int main (){
while (cin>>n){
int flag,temp;
int ans=maxn;
memset (visit,,sizeof visit);
for (int i=;i<n;i++){
cin>>a[i];
}
a[n]=;
for (int i=;i<n;i++){
cin>>b[i];
}
int j=;
ans=; //求不用处理的元素个数
for (int i=;i<n;i++){
if (a[j]!=b[i])
continue ;
j++;
ans++;
}
cout<<n-ans<<endl;
}
return ;
}
CodeForces 187A Permutations的更多相关文章
- 贪心 CodeForces 124B Permutations
题目传送门 /* 贪心:全排列函数使用,更新最值 */ #include <cstdio> #include <algorithm> #include <cstring& ...
- CodeForces 124B Permutations
http://codeforces.com/problemset/problem/124/B Description You are given nk-digit integers. You have ...
- CSU训练分类
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces 285 E. Positions in Permutations
\(>Codeforces \space 285 E. Positions in Permutations<\) 题目大意 : 定义一个长度为 \(n\) 的排列中第 \(i\) 个元素是 ...
- Codeforces Round #198 (Div. 2) E. Iahub and Permutations —— 容斥原理
题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 sec ...
- Codeforces Round #337 Alphabet Permutations
E. Alphabet Permutations time limit per test: 1 second memory limit per test: 512 megabytes input: ...
- codeforces 341C Iahub and Permutations(组合数dp)
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces 463D Gargari and Permutations
http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...
随机推荐
- python 连接操作数据库(一)
一.下面我们所说的就是连接mysql的应用: 1.其实在python中连接操作mysql的模块有多个,在这里我只给大家演示pymysql这一个模块(其实我是感觉它比较好用而已): pymysql是第三 ...
- 2.Perl基础系列之入门
官网提供的入门链接:http://perldoc.perl.org/perlintro.html 语法概述 Perl的安装步骤省略,直接去官网下载并按照提示安装即可. 如果Perl安装没问题,那么运行 ...
- 转:nginx location匹配规则
location匹配命令 ~ #波浪线表示执行一个正则匹配,区分大小写~* #表示执行一个正则匹配,不区分大小写^~ #^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配 ...
- mysql索引分类及注意事项
MYSQL索引主要分为四类:主键索引,普通索引(聚合,非聚合),唯一索引,全文索引 全文索引,主要是针对对文件,文本的检索, 比如文章, 全文索引针对MyISAM有用. 索引的原理:利用二叉树(哈希表 ...
- Struts2+JQuery+JSON实现异步交互
1.环境 jquery:jquery-1.9.0.min.js struts2:基本包就不说了,就说说应用json的包,主要有struts2-json-plugin-2.3.8.jar json:js ...
- Android 操作系统的内存回收机制[转]
转自:http://www.ibm.com/developerworks/cn/opensource/os-cn-android-mmry-rcycl/ Android APP 的运行环境 Andro ...
- 剑指offer-面试题1:赋值运算符函数
题目:如下为类型CMyString的声明,请为该类型添加赋值运算符函数 class CMyString { public: CMyString(char *pData=NULL); CMyString ...
- 为什么学微信小程序开发
微信小程序是什么? 触手可得,不用安装,不体验过自己是想不到的 ---张小龙 小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜 一下即可打开应用.也体现了“用 ...
- C#代码控制 zip rar 解压缩
首先 解压ZIP的方法: #region 解压ZIP /// <summary> /// 解压ZIP /// </summary> /// <param name=&qu ...
- Unity 调用android插件
1. Unity的Bundle Identifier必须和你的android报名一致 Activity和View的区别: Activity应该是一个展示页面,View是页面上一些按钮视图等等. 如何调 ...