题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少次。

析:这个题,没什么算法,就是模拟呗,不过要注意时间,不能TLE,所以我们就得提前把所有的位置都存下来,让查找的时间变成 O(1),否则就会超时,可以用两个数组,也可以用map,一个存编号,一个存位置,

然后运行完后再交换就行了。

代码如下:

#include <iostream>
#include <cstdio>
#include <map>
#include <cmath> using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
map<int, int> mp;
map<int, int> mps;
int main(){
int n, m, k, x;
while(scanf("%d %d %d", &n, &m, &k) == 3){
for(int i = 0; i < n; ++i){
scanf("%d", &x);
mp[x] = i+1;
mps[i+1] = x;
} LL ans = 0;
for(int i = 0; i < m; ++i){
scanf("%d", &x);
int t = mp[x];
ans += (LL)ceil((double)t/k);
if(t == 1) continue;
swap(mp[mps[t]], mp[mps[t-1]]);
swap(mps[t], mps[t-1]);
}
printf("%lld\n", ans);
}
return 0;
}

CoderForces 518C Anya and Smartphone (模拟)的更多相关文章

  1. codeforces 518C. Anya and Smartphone

    C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. C. Anya and Smartphone

    C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #293 (Div. 2) C. Anya and Smartphone 数学题

    C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #293 (Div. 2)

    A. Vitaly and Strings 题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串 字符转处理:字典序排序 很巧妙的方法,因为s < t,只要找比t字典 ...

  7. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  8. coderforces #387 Servers(模拟)

    Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  9. Codeforces Round #366 (Div. 2) C 模拟queue

    C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. Archiva与maven配置使用

    在之前的博文里头已经介绍了Archiva私服的使用,本文主要介绍,如何与maven进行配置,在进行maven使用的时候可以自动上传至Archiva上 1.设置maven的用户配置,到maven的安装目 ...

  2. sorting--codility

    lesson 6: sorting 1. Distinct 2. Triangle 2. MaxProductOfThree 4. NumberOfDiscIntersections lesson 6 ...

  3. JpGraph使用详解

    微信平台开发的推广支持应用里,为了满足用户渠道推广分析的需要,公众平台提供了生成带参数二维码的接口.使用该接口可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送,借此可以通过统计不 ...

  4. linux svn soeasy

    http://blog.163.com/longsu2010@yeah/blog/static/173612348201202114212933/

  5. Linux C 一些函数 所属头文件

    1. Linux中一些头文件的作用:<assert.h>:ANSI C.提供断言,assert(表达式)<glib.h>:GCC.GTK,GNOME的基础库,提供很多有用的函数 ...

  6. 给iOS开发新手送点福利,简述UIPageControl的属性和用法

    UIPageControl 1.   numberOfPages // 设置有多少页 默认为0 [pageControl setNumberOfPages:kImageCount]; 2.   cur ...

  7. uwsgi配置文件的一些细节,uwsgi错误invalid request block size

    [uwsgi] #socket = #这种是使用代理方式访问的,不能直接输入端口访问,要搭配其他的HTTP服务比如NGINX,设置反向代理 http =: #这种是直接可以输入IP端口访问 modul ...

  8. Python中的strip()函数的用法

    函数:string.strip() Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 一.函数说明 strip() 语法:str.strip([rm]); 参数说明 rm ...

  9. C#串口编程测试收发

    原文:http://www.cnblogs.com/vsdot/archive/2013/04/23/3263348.html   基本传递方法:RS232传输要有1位起始位,8位数据位.1位校验位( ...

  10. leetcode88

    public class Solution { public void Merge(int[] nums1, int m, int[] nums2, int n) { //for (int i = 0 ...