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 ...
随机推荐
- c#以文件流的形式输出xml(可以解决内存溢出)-XmlTextWriter
1.XmlTextWriter 表示提供快速.非缓存.只进方法的编写器,该方法生成包含 XML 数据(这些数据符合 W3C 可扩展标记语言 (XML) 1.0 和“XML 中的命名空间”建议)的流或文 ...
- mac终端 使用摘要
Root (拥有对此计算机的所有权限) 查看当前用户:who 切换到root(默认系统是不会使用root的):sudo -s 然后输入密码 更改密码:passwd
- USB-CSW之旅
前面总结了usb mass storage的枚举过程,如果所有枚举正常,那么会进入bulkonly协议定义的数据交流,在这个数据包里面还包含了SCSI的协议. Bulkonly协议usbmassbul ...
- 从Qt4到Qt5的,主要的进化有三(对于QtWidget的精简和优化会很有限)
从Qt4到Qt5的,主要的进化有三:1 语言的进化,原来是基于C++(qtwidget)和XML(.ui),现在添加了QML(QtQuick)+JS(v8)的架构.2 绘图系统的进化,原先基于QPai ...
- SqlBulkCopy 类
1.SqlBulkCopy 简介 Microsoft SQL Server 提供一个称为 bcp 的流行的命令提示符实用工具,用于将数据从一个表移动到另一个表(表既可以在同一个服务器上,也可以在不同 ...
- 你真的会玩SQL吗?透视转换
原文:你真的会玩SQL吗?透视转换 透视转换是一种行列互转的技术,在转过程中可能执行聚合操作,应用非常广泛. 本章与 你真的会玩SQL吗?数据聚合 内容比较重要,还涉及到 你真的会玩SQL吗?Case ...
- 【C语言用法】C语言的函数“重载”
由于平时很少用到__attribute__定义函数或者变量的符号属性,所以很难想象C语言可以向C++一样进行函数或者变量的重载. 首先,复习一下有关强符号与弱符号的概念和编译器对强弱符号的处理规则: ...
- 剑指offer-面试题12.打印1到最大的n位数
题目:输入数字n,按照打印出从1最大的n位10进制数.比如3,则 打印出1.2.3一直到最大的3位数即999 1.你觉得如果面试会有这么简单的题,那 只能说明你---太天真. 2.n=3尚可,如果n= ...
- poj 3301 Texas Trip(几何+三分)
Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in ...
- IOS 网络判断
Reachability *connectionNetWork= [Reachability reachabilityForInternetConnection] ; int status = [co ...