Codeforces Round #293 (Div. 2) C. Anya and Smartphone

 

题目地址:http://codeforces.com/contest/518/problem/C

 1 /*  2  无算法  3  统计划屏的次数,如果在第一屏则不用,只要每次交换与前面数字的顺序就行了  4  注意:ans开long long  5  好吧,这道题是最水的,主要是题目很难读懂,可以从Note里猜出题目意思  6 */  7 #include <cstdio>  8 #include <iostream>  9 #include <algorithm> 10 #include <cmath> 11 #include <cstring> 12 #include <string> 13 #include <map> 14 using namespace std; 15 16 const int MAXN = 1e5 + 10; 17 const int INF = 0x3f3f3f3f; 18 19 int num[MAXN]; 20 int pos[MAXN]; 21 22 int main(void) 23 { 24 //freopen ("C.in", "r", stdin); 25 26 int n, m, k; 27 28 while (~scanf ("%d%d%d", &n, &m, &k)) 29  { 30 int x; 31 for (int i=1; i<=n; ++i) 32  { 33 scanf ("%d", &x); 34 pos[x] = i; 35 num[i] = x; 36  } 37 long long ans = 0; 38 for (int i=1; i<=m; ++i) 39  { 40 scanf ("%d", &x); 41 42 int p = pos[x]; 43 ans += (p / k); 44 if (p % k) ans += 1; 45 if (p == 1) continue; 46 47 int y = num[p-1]; 48 num[p-1] = x; 49 num[p] = y; 50 pos[y]++; pos[x]--; 51  } 52 53 printf ("%I64d\n", ans); 54  } 55 56 return 0; 57 }

 

你可能感兴趣的:(codeforces)