反向思维,先求数组中不用处理的元素个数,再用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的更多相关文章

  1. 贪心 CodeForces 124B Permutations

    题目传送门 /* 贪心:全排列函数使用,更新最值 */ #include <cstdio> #include <algorithm> #include <cstring& ...

  2. CodeForces 124B Permutations

    http://codeforces.com/problemset/problem/124/B Description You are given nk-digit integers. You have ...

  3. CSU训练分类

    √√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...

  4. Codeforces Round #485 (Div. 2) E. Petr and Permutations

    Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...

  5. Codeforces 285 E. Positions in Permutations

    \(>Codeforces \space 285 E. Positions in Permutations<\) 题目大意 : 定义一个长度为 \(n\) 的排列中第 \(i\) 个元素是 ...

  6. 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 ...

  7. Codeforces Round #337 Alphabet Permutations

    E. Alphabet Permutations time limit per test:  1 second memory limit per test:  512 megabytes input: ...

  8. codeforces 341C Iahub and Permutations(组合数dp)

    C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. Codeforces 463D Gargari and Permutations

    http://codeforces.com/problemset/problem/463/D 题意:给出k个排列,问这k个排列的最长公共子序列的长度. 思路:只考虑其中一个的dp:f[i]=max(f ...

随机推荐

  1. Python解析json字符串

    {"status":0,"result":{"location":{"lng":116.47847460177,&quo ...

  2. 我和Python的第一次亲密接触 - 零基础入门学习Python001

    我和Python的第一次亲密接触 让编程改变世界 Change the world by program 小甲鱼经常说,学习一门编程语言就是要深入其中,要把编程语言想象为你的女朋友你的情人,这样你学习 ...

  3. VS2012 的MVC4实例

    原文链接:http://wenku.baidu.com/link?url=nkq-UZd-Ui83Nuoh66n4KqdwK4V_zzKqakmmG6VBgq2BfWlMiPhz1JXN9R3CWxN ...

  4. mysql null值转换

    1.如果为空返回0 select ifnull(null,0) 2.如果为空返回0,否则返回1 select if(isnull(col),0,1) as col.

  5. android sdk 如何重新生成debug.keystore

    1)首先你要确定你安装的JDK位置,Windows->Preferences->Java->Installed JREs,你可以看到是Jre的location,再在dos cmd模式 ...

  6. 2014.8.4我出的模拟赛【你的名字叫czy是吧】

    你的名字叫czy是吧 (mynameisczy.pas/.c/.cpp) 尽管czy放了那么多只NTR酋长,也没能拦住黄巨大.黄巨大和czy相遇了…… “你的名字叫czy是吧” “……” “我们来单挑 ...

  7. Linux Ubuntu download

    下载地址:http://www.ubuntu.com/download/ Ubuntu桌面用户版 符合用户个性的版本

  8. Path Sum II 解答

    Question Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the ...

  9. python socket之tcp服务器与客户端demo

    python socket之tcp服务器与客户端demo 作者:vpoet mails:vpoet_sir@163.com server: # -*- coding: cp936 -*- ''' 建立 ...

  10. 操作系统基本概念(内核态与用户态、操作系统结构)-by sixleaves

    内核态与用户态(为什么存在这种机制.程序应处于哪个状态.如何判断当前所处状态.哪些功能需要内核态.如何实现这种机制) 1.首先我们应该思考清楚为什么会有内核态和用户态?(为什么存在这种机制) 因为计算 ...