题意:给定一个手机,然后一共有 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. 使用_beginThreadex创建多线程(C语言版多线程)

    _beginThreadex创建多线程解读 一.需要的头文件支持 #include <process.h>         // for _beginthread() 需要的设置:Proj ...

  2. SQL 知识及用法备忘录

    ---查询当前数据库一共有多少张表 ) from sysobjects where xtype='U' ---查询当前数据库有多少张视图 ) from sysobjects where xtype=' ...

  3. Mac上如何把图片中的文字转换成word/pdf文字

    如何把图片文字转换成word文字? - 知乎 https://www.zhihu.com/question/25488536 在 OneNote for Mac 中插入的圖片複製文字 - OneNot ...

  4. 折腾一天,获取下列多选框的所有选中值,原生js可直接通过obj.val()来获取,可jq不行,要通过循环取值来获取;

    折腾一天,获取下列多选框的所有选中值,原生js可直接通过obj.val()来获取,可jq不行,要通过循环取值来获取;

  5. 停止调试 IIS 不退出

    在VS主面板打开:工具->选项->调试->编辑继续   取消选中[启用"编辑并继续"] 就可以(不过这是针对所有的调试). 若只想对单个项目进行设置,可以选择自己 ...

  6. Java前期(静态)绑定和后期(动态)绑定

    Java前期(静态)绑定和后期(动态)绑定 程序绑定的概念:绑定指的是一个方法的调用与方法所在的类(方法主体)关联起来.对java来说,绑定分为静态绑定和动态绑定:或者叫做前期绑定和后期绑定. 静态绑 ...

  7. c#二维码建立与识别

    QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8" ...

  8. python 黑魔法 ---上下文管理器(contextor)

    所谓上下文 计算机上下文(Context)对于我而言,一直是一个很抽象的名词.就像形而上一样,经常听见有人说,但是无法和现实认知世界相结合. 最直观的上下文,莫过于小学的语文课,经常会问联系上下文,推 ...

  9. Oracle Tip: Choosing an efficient design for Boolean column values

    Takeaway: When designing a database table structure, it's important to choose an efficient strategy ...

  10. 【332】Machine Learning

    Reference: 决策树方法-对买电脑进行分类预测 Reference: 最邻近规则分类(K-Nearest Neighbor)KNN算法应用 Reference: python 内建函数 str ...