题意:给定一个手机,然后一共有 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. 输入和输出(read,recv,recvmsg...和write,writev,writemsg)

    每一个TCP套接口有一个发送缓冲区,可以用SO_SNDBUF套接口选项来改变这个缓冲区的大小. 应用进程调用 write时,内核从应用进程的缓冲区中拷贝所有数据到套接口的发送缓冲区.如果套接口的发送缓 ...

  2. Spring Bean单例与线程安全

    一.Spring单例模式及线程安全 Spring框架中的Bean,或者说组件,获取实例的时候都是默认单例模式,这是在多线程开发的时候需要尤其注意的地方. 单例模式的意思是只有一个实例,例如在Sprin ...

  3. Programming Languages: Application and Interpretation

    http://cs.brown.edu/courses/cs173/2012/book/ 1 Introduction 1.1 Our Philosophy 1.2 The Structure of ...

  4. CentOS 6.5 下keepalived服务的配置

    CentOS 6.5 下keepalived服务的配置 参考网站: http://zhangxugg-163-com.iteye.com/blog/1665419 http://www.2cto.co ...

  5. springboot利用MockMvc测试controller控制器

    主要记录一下控制器的测试,service这些类测试相对简单些(可测试性强) API测试需求比较简单: ① 需要返回正确的http状态码 200 ② 需要返回json数据,并且不能返回未经捕获的系统异常 ...

  6. CFGym 100198G 题解

    一.题目链接 http://codeforces.com/gym/100198/problem/G 二.题意 看样例就能明白,写表达式解析器. 三 .思路 一看这题目,立马就会想到“后缀表达式”,考虑 ...

  7. [Windows报错]要求的函数不受支持、这可能是由于 CredSSP 加密 Oracle 修正

    版本说明: 服务器版本:Windows Server 2008 R2 SP1(虚机) 客户端版本:Windows 10 家庭版   问题描述: 使用Windows远程桌面连接时弹出如下描述的错误,如图 ...

  8. 利用U盘安装Redhat-server-Linux-7.1

    利用U盘安装Redhat-server-Linux-7.1 [原]红帽 Red Hat Linux相关产品iso镜像下载[百度云]

  9. JDK、Spring、Quartz等几种不同定时器的用法,以及cronExpression表达式定义

    referenc:https://blog.csdn.net/clementad/article/details/42042111 下面介绍几种常用的定时器及其实现方法: 第一种:Timer和Time ...

  10. Back to CNBLOG

    突然发现自己很久都没有写过博客了,感觉有点愧对程序员这个称号... 任重道远,要做的东西很多,越来发现,坚持是最难的,例如写博客. 但起码有有个开始,要有个开始去分享自己的经历,去让别人也知道,你是怎 ...