CodeForces Round #119 (187A) - Permutations
来源:互联网 发布:农业大数据的应用 编辑:程序博客网 时间:2024/06/06 10:41
昨晚比赛回寝室才做的~~A了两道水题~~这题看了下..很晚了~也没想法..就睡了..
这题突破点或者说关键之处就在第二列最后一个数在第一列中的位置...
设第二列最后一个数为x...设x在第一列位置为i..1~i的顺序是符合第二列中数字前后关系的话..那易得所需的最小移动步数就是不断抽第一列最后的数使得x到第n位..
若是1~i不是按第二列的数字关系递增的话..也很好想到将x移到第k+1位..其中1~k是最长的按第二列的数字关系递增的..再不断的抽第一列最后的数使得x到第n位..
Program:
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<cmath>#include<queue>#define oo 2000000000#define ll long longusing namespace std;int sa[200005],sb[200005],a[200005],b[200005];int main(){ int i,n,ans; scanf("%d",&n); for (i=1;i<=n;i++) { scanf("%d",&a[i]); sa[a[i]]=i; } for (i=1;i<=n;i++) { scanf("%d",&b[i]); sb[b[i]]=i; } for (i=2;i<=n;i++) if (sb[a[i-1]]>sb[a[i]]) break; i--; if (i!=sa[b[n]]) ans=n-i; else ans=n-sa[b[n]]; printf("%d\n",ans); return 0;}
- CodeForces Round #119 (187A) - Permutations
- Codeforces Round #175 (Div. 2)---A. Slightly Decreasing Permutations
- Codeforces Round #119 (Div. 2) A题
- codeforces round 119 div2 A-D
- codeforces round#283 A
- Codeforces Round #234A
- Codeforces Round #439 A
- codeforces A. Slightly Decreasing Permutations 题解
- CodeForces 296A Yaroslav and Permutations
- Codeforces Round #175 DIV2 E Positions in Permutations
- Codeforces Round #175 (Div. 2) E Positions in Permutations
- Codeforces Round #285 Div.1 B Misha and Permutations Summation
- Codeforces Round #153 (Div. 1)BPlaying with Permutations
- Codeforces Beta Round #92 (Div. 2 Only) B. Permutations
- Permutations CodeForces
- codeforces div2 round#231 A
- codeforces div2 round#230 A
- Codeforces Round #2A Winner
- C C++ OC iOS面试重点问题(一)
- #119div2 D
- Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)
- s3c6410的UART设备驱动(1)
- 第十三周实验指导(一)
- CodeForces Round #119 (187A) - Permutations
- c2-3-main-frm_10501-10700渲染日志
- 缓存命中率
- font .c
- Ubuntu Linux学习笔记1
- Java NIO原理和使用
- Makefile sh
- temp classloader.
- 《C和指针》学习笔记四/函数/