Codeforces Round #293 (Div. 2) C. Anya and Smartphone 数学题
1 second
256 megabytes
standard input
standard output
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly n applications, each application has its own icon. The icons are located on different screens, one screen contains k icons. The icons from the first to the k-th one are located on the first screen, from the (k + 1)-th to the 2k-th ones are on the second screen and so on (the last screen may be partially empty).
Initially the smartphone menu is showing the screen number 1. To launch the application with the icon located on the screen t, Anya needs to make the following gestures: first she scrolls to the required screen number t, by making t - 1 gestures (if the icon is on the screen t), and then make another gesture — press the icon of the required application exactly once to launch it.
After the application is launched, the menu returns to the first screen. That is, to launch the next application you need to scroll through the menu again starting from the screen number 1.
All applications are numbered from 1 to n. We know a certain order in which the icons of the applications are located in the menu at the beginning, but it changes as long as you use the operating system. Berdroid is intelligent system, so it changes the order of the icons by moving the more frequently used icons to the beginning of the list. Formally, right after an application is launched, Berdroid swaps the application icon and the icon of a preceding application (that is, the icon of an application on the position that is smaller by one in the order of menu). The preceding icon may possibly be located on the adjacent screen. The only exception is when the icon of the launched application already occupies the first place, in this case the icon arrangement doesn't change.
Anya has planned the order in which she will launch applications. How many gestures should Anya make to launch the applications in the planned order?
Note that one application may be launched multiple times.
The first line of the input contains three numbers n, m, k (1 ≤ n, m, k ≤ 105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains n integers, permutation a1, a2, ..., an — the initial order of icons from left to right in the menu (from the first to the last one), ai — is the id of the application, whose icon goes i-th in the menu. Each integer from 1 to n occurs exactly once among ai.
The third line contains m integers b1, b2, ..., bm(1 ≤ bi ≤ n) — the ids of the launched applications in the planned order. One application may be launched multiple times.
Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.
- 8 3 3
1 2 3 4 5 6 7 8
7 8 1
- 7
- 5 4 2
3 1 5 2 4
4 4 4 4
- 8
In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch it Anya makes 3 gestures.
After application 8 is launched, we get configuration (123)(457)(86). To launch it Anya makes 3 gestures.
After application 1 is launched, the arrangement of icons in the menu doesn't change. To launch it Anya makes 1 gesture.
In total, Anya makes 7 gestures.
题意:有一个智能手机,有n个应用,要打开m个应用,智能机每页只能放k个应用
然后问你这些应用需要多少次操作
每次翻页,和点击应用需要一次操作
题解:拿两个数组,其中一个数组记录这个位置的是哪个应用,和这个应用在哪个位置
然后胡乱搞一搞就好了
- int n,m,k;
- int step[maxn];
- int loat[maxn];
- int main()
- {
- cin>>n>>m>>k;
- int tmp;
- for(int i=;i<n;i++)
- {
- cin>>tmp;
- step[tmp]=i;
- loat[i]=tmp;
- }
- LL ans=;
- for(int i=;i<m;i++)
- {
- cin>>tmp;
- ans+=step[tmp]/k+;
- if(step[tmp]==)
- continue;
- loat[step[tmp]]=loat[step[tmp]-];
- step[tmp]--;
- step[loat[step[tmp]]]++;
- loat[step[tmp]]=tmp;
- }
- cout<<ans<<endl;
- }
Codeforces Round #293 (Div. 2) C. Anya and Smartphone 数学题的更多相关文章
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- 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 模拟
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 #297 Div. 2] E. Anya and Cubes
http://codeforces.com/contest/525/problem/E 学习了传说中的折半DFS/双向DFS 先搜前一半数,记录结果,然后再搜后一半数,匹配之前结果. #include ...
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- iptables NAT规则【转】
nat表需要的三个链: 1.PREROUTING:可以在这里定义进行目的NAT的规则,因为路由器进行路由时只检查数据包的目的ip地址,所以为了使数据包得以正确路由,我们必须在路由之前就进行目的NAT; ...
- 『实践』Java Web开发之分页(ajax)
1.需要用到的jar包.js文件 JSONArray().fromObject()需要的jar包: (1)commons-beanutils-1.8.3.jar (2)commons-collecti ...
- 打造 Laravel 优美架构 谈可维护性与弹性设计
转载:https://juejin.im/post/5be4475c518825170559c044
- asp.net mvc 本地化 默认的错误提示
System.ComponentModel.DataAnnotations 给我们提供了一些特性来直接对model的属性进行验证和约束, 同时也提供了 ErrorMessageResourceName ...
- java 二叉树遍历
package com.lever; import java.util.LinkedList;import java.util.Queue; /** * 二叉树遍历 * @author lckxxy ...
- Javascript之对象的创建
面向对象语言有一个非常显著的标志,那就是它们都有类的概念,通过类之间的继承就可以达到任意创建具有相同属性方法的对象.而在ECMAScript中并没有类的概念,它把对象定义为:无序属性的集合,其属性包含 ...
- Oracle学习笔记:trunc函数
在Oracle中可以使用trunc函数进行日期截取和数字截取,具体使用方法如下: 1.trunc(for dates) 日期截取 语法:trunc(date,[fmt]) select trunc(s ...
- Python线程和进程
一.进程 程序并不能单独和运行只有将程序装载到内存中,系统为他分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别在于:程序是指令的集合,它是进程的静态描述文本:进程是程序的一次执行活动, ...
- N皇后问题的实现
N皇后问题是一个经典的问题,是回溯算法的典型案例.它是由国际西洋棋棋手马克斯·贝瑟尔于1848年提出的八皇后问题延伸而来的,具体要求如下:在N*N的方格棋盘放置N个皇后,使她们彼此不相互攻击,即任意2 ...
- ref:CodeIgniter框架内核设计缺陷可能导致任意代码执行
ref:https://www.seebug.org/vuldb/ssvid-96217 简要描述: 为准备乌云深圳沙龙,准备几个0day做案例. 官方承认这个问题,说明会发布补丁,但不愿承认这是个『 ...