CoderForces 518C Anya and Smartphone (模拟)
题意:给定一个手机,然后一共有 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 (模拟)的更多相关文章
- codeforces 518C. Anya and Smartphone
C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...
- C. Anya and Smartphone
C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #293 (Div. 2)
A. Vitaly and Strings 题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串 字符转处理:字典序排序 很巧妙的方法,因为s < t,只要找比t字典 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- 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 ...
随机推荐
- 根据tomcat的日志判断web的发布路径以及服务路径
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.unde ...
- linux shell 模拟post请求
Linux 下curl模拟Http 的get or post请求. 一.get请求 curl "http://www.baidu.com" 如果这里的URL指向的是一个文件或 ...
- VirtualBox的端口映射其实很好理解
还是和以前百度的另一个知识点一样,我真不明白网上那些人要做什么,明明很简单的事,干嘛非要讲的那么复杂,就是为了让人觉得你很高手?很厉害? 名称:随便起的,基于好记的原则,你的什么应用在使用这一条端口转 ...
- MySQL分段统计SQL写法 与 Mybatis 异常 java.math.BigDecimal cannot be cast to java.lang.Integer
mysql> select end) as '<60', end) as '60~69', end) as '70~79', end) as '80~89', end) as '>= ...
- cocos命令行生成项目
cocos命令行生成项目: cocos new GoodDay(项目名称) -p com.boleban.www(包名字) -l cpp(项目类型) -d D:\DevProject\cocos2dx ...
- Boost C++ 库 中文教程(全)
Boost C++ 库 目录 第 1 章 简介 第 2 章 智能指针 第 3 章 函数对象 第 4 章 事件处理 第 5 章 字符串处理 第 6 章 多线程 第 7 章 异步输入输出 第 8 章 进程 ...
- mysql-Innodb事务隔离级别-repeatable read详解(转)
一.事务隔离级别 ANSI/ISO SQL标准定义了4中事务隔离级别:未提交读(read uncommitted),提交读(read committed),重复读(repeatable read),串 ...
- java 文件指针复位
BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream("userremain.l ...
- 不用写代码就能实现深度学习?手把手教你用英伟达 DIGITS 解决图像分类问题
2006年,机器学习界泰斗Hinton,在Science上发表了一篇使用深度神经网络进行维数约简的论文 ,自此,神经网络再次走进人们的视野,进而引发了一场深度学习革命.深度学习之所以如此受关注,是因为 ...
- Hyberledger-Fabric 1.00 RPC学习(1)
参考:http://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html 本文的目的就是基于Hyperledger Fabr ...