codeforces 518 C. Anya and Smartphone

工业互联网工控安全与工业质检AI大模型建设方案.pptx 立即下载

C. Anya and Smartphone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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.

Output

Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order.

Sample test(s)
input
8 3 3
1 2 3 4 5 6 7 8
7 8 1
output
7
input
5 4 2
3 1 5 2 4
4 4 4 4
output
8
Note

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.


题目链接:http://codeforces.com/problemset/problem/518/C


题目大意:智能手机上有n个软件,编号1-n不重复,k和软件在同一个页面。启动一个软件需要进行翻页和点击两种操作,每次从第一个页面开始翻页,软件被启动后,其编号与前一个软件的位置交换,如果位置是第一个,不需要交换。询问m次,每次启动一个对应编号的软件,求启动所有软件一共需要执行的操作次数。


解题思路:数组a[]记录软件编号,数组b[]记录每个编号的软件对应的位置,每次软件被启动后b[]值被更新,记录新的位置,每个软件被启动的操作步骤数为b[]/k+1。


代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const maxn=100020;
int b[maxn],a[maxn];
int main()
{
    int n,k,i,x;
    long long m,ans=0;
    scanf("%d%I64d%d",&n,&m,&k);
    ans=m;     //一共点击的操作次数
    for(i=0;i<n;i++)
	{
        scanf("%d",&a[i]);
		b[a[i]]=i;
	}
    for(i=0;i<m;i++)
    {
        scanf("%d",&x);
		ans+= b[x]/k;
		if(b[x]!=0)
		{

			b[a[b[x]-1]]++;    //前一个软件位置与当前软件位置交换
			b[x]--;
			swap(a[b[x]+1],a[b[x]]);
		}
    }
    printf("%I64d\n", ans);
    return 0;
}





深入解析HAL_UART_Receive_IT:如何高效配置串口中断接收 本文深入解析了STM32 HAL库中`HAL_UART_Receive_IT`函数的工作原理与高效配置方法。该函数并非直接接收数据,而是作为中断接收的启动器和配置器,通过开启相关中断,由`UART_Receive_IT`在后台完成数据搬运。文章详细对比了中断与轮询模式的区别,并提供了不定长数据接收的完整实战流程、常见问题避坑指南及高级应用技巧,帮助开发者构建稳定高效的串口通信。 阅读详情

相关推荐

SAP PCE私有云MM02修改物料主数据基本单位报错

当前发现只有改为AAAADL(无量纲)单位时会报错,其他的正常。一开始以为配置的ISO码换算有问题,对配置排查后,排除配置问题。最后发现是PCE当前版本的原因,需要打上NOTE。SAP PCE私有云在没有库存和业务单据的情况下,MM02修改物料主数据基本单位报错“EA CPZP MK000000000000:PCS 不可转换为”,详见截图。点击【显示错误】,提示EA CPZP MK000000000000:PCS 不可转换为。从SAP FOR ME下载NOTE 3531359,链接。

dingqing86的专栏 519

CodeForces 518C Anya and Smartphone

Description 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 differe

每一次AC都是一种感动 593

保姆级教程:用YOLOv8n模型在RKNN和Horizon平台完成目标检测(附C++部署代码与性能实测)

本文提供了一份详尽的YOLOv8n模型在RKNN和Horizon平台上的部署指南,涵盖环境配置、模型优化、跨平台适配及性能调优。通过实战案例和C++部署代码,帮助开发者在嵌入式设备上高效实现目标检测,显著提升推理性能。

weixin_42659194的博客 468

CodeForces - 518C Anya and Smartphone(链表)

题意: 最近Anya买了一个B卓系统的手机,手机上面有n个应用,对应n个图标。 但是屏幕有限,每个屏幕只能容纳k个图标,现在如果你要寻找第k个屏幕上面的应用, 那么你要执行k-1次滑动操作+1次点击操作。当应用启动之后,又重新回到1屏幕。 但是B卓操作系统是个非常屌的操作系统,它能改变图标的顺序,将更频繁地使用图标移动到列表的开始,即除了第一个以外,每打开一个应用就会和前面的应

小G的ACM之路 1176

第一章 Cheat Enginee(CE)使用指南

Cheat Engine核心功能详细说明(以植物大战僵尸为例) 教你修改单机游戏。

m0_74545731的博客 1万+

Chromatix_AEC—深入解析曝光表配置与传感器参数计算

本文深入解析高通Chromatix AEC模块中的曝光表配置与传感器参数计算,详细介绍了自动曝光控制(AEC)的核心概念、首行曝光时间计算、行时间与曝光模式对比、帧率计算逻辑以及曝光表高级配置技巧。通过实战案例展示如何优化传感器参数联调,帮助开发者掌握Chromatix工具在摄像头系统中的关键应用。

266

Codeforces 518C Anya and Smartphone【思维+模拟】

C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anya has bought a new smartphone that uses Berd

mengxiang000000 592

【详细】芯片设计全流程(包括每个流程需要用到的工具以及需要参与的工作人员)

一颗芯片的诞生经历了设计、制造和测试(分别对应集成电路产业链的设计业、制造业和封测业),而每一步都包含了复杂的步骤和流程。 图0-1 集成电路产业链 现在,我们重点介绍芯片设计的全流程以及每个流程需要用到的设计工具和需要参与的工作人员。 一、IC设计分类 首先对IC设计的分类做个介绍,如图1-1所示。 图1-1 IC设计分类 如图1-1所示,IC设计可以粗分为数字IC设计和射频/模拟IC设计,数字IC设计又可分为ASIC设计和FPGA/CPLD设计,此外还有一部分IC设计.

qq_36045093的博客 8万+

codeforces 518C. Anya and Smartphone

C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anya has bought a new smartphone that usesBe...

weixin_30838921的博客 337

三种 绘制奈奎斯特曲线 的方法

如何绘制Nyquist曲线 提供三种绘制方法,其中使用最广泛的是概略图绘制方法 ①解析法绘制 ②概略图法绘制 ③MATLAB绘制

weixin_46664967的博客 6万+

鱼眼相机去畸变(图像拉直/展开/矫正)算法及实战总结

1、算法说明经纬度矫正法, 可以把鱼眼图想象成半个地球, 然后将地球展开成地图,经纬度矫正法主要是利用几何原理, 对图像进行展开矫正。经过P点的入射光线没有透镜的话,本应交于相机成像平面的e点。然而,经过鱼眼相机的折射,光线会交于相机成像平面的d点,就产生了畸变,因此畸变图像整体上呈现出像素朝图像中心点聚集的态势。而去畸变,就是将折射到d点的点,重新映射回到e点,因此去畸变之后的图像与原始的鱼眼图像相比,仿佛是把向心聚集的像素又重新向四周铺展开来。AVM环视系统——鱼眼相机去畸变算法 - 知乎。

大胡子大叔的专栏 2万+

CodeForces - 518C Anya and Smartphone

题意: 安雅购买了一只带有Berdroid操作系统的智能手机。智能手机菜单中有n个应用,每个应用程序都有其自己的图标。每个应用的图标都在相应的屏幕上,一个屏幕包含ķ个图标。第1个应用到第k个应用的图标位于第一个屏幕上,从第(k + 1)个至第2k个应用在第二个屏幕上,依次类推(最后屏幕可以是部分为空) 。   开始的时候,智能手机显示的屏幕是第一个屏幕,为了去启动第t个屏幕上的应用,

DT2131 606

基于STM32、HAL库的TLV320AIC3204IRHBR音频接口芯片驱动程序设计

* 开启所有数字部分 */#define TLV320AIC3204_REG_LEFT_HEADPHONE_OUT_VOLUME 0x0C /* 左声道耳机输出音量 */#define TLV320AIC3204_REG_DIGITAL_AUDIO_PATH_CONTROL 0x05 /* 数字音频路径控制 */#define TLV320AIC3204_REG_ANALOG_HP_FILTER_CONTROL 0x34 /* 模拟耳机滤波器控制 *//* 最大音量 */

corlin6688的博客 520

Codeforces Round #293 (Div. 2) C.Anya and Smartphone(模拟)

题目地址:http://codeforces.com/problemset/problem/518/C 思路:模拟即可 #include #include #include #include #define debu using namespace std; const int maxn=1e5+50; int n,m,k; long long ans=0; int order[maxn]

哆啦AC梦的博客 585

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

noj 1046 第K回文数

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和图片上传 LaTex数学公式 UML序列图和流程图 离线写博客 导入导出Markdown文件 丰富的快捷键 快捷键 加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl

ysCover 1224

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

codeforces 538 A.Cutting Banner

A. Cutting Banner time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A large banner with word CODEFORCES was o

ysCover 1127

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

hdu 5202 Rikka with string(模拟)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 625    Accepted Submission(s): 244 Problem Description As we know, Ri

ysCover 1058

noj 1006 多项式乘法

noj 模拟

ysCover 943

Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)

B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera loves his garden, where n fruit

ysCover 878

蓝桥杯 PREV-2 打印十字图 (简单对称模拟)

历届试题 打印十字图   时间限制:1.0s   内存限制:256.0MB     问题描述 小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示: ..$$$$$$$$$$$$$.. ..$...........$.. $$$.$$$$$$$$$.$$$ $...$.......$...$ $.$$$.$$$$$.$$$.$ $.$...$

ysCover 870

hdu 2074 叠筐

叠筐 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16555 Accepted Submission(s): 4320Problem Description 需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐

ysCover 792

noj 1005 多项式加法

模拟 noj

ysCover 748

codeforces B. Petya and Exam (模拟)

B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It's hard times now. Today Petya needs to

ysCover 734

noj 1073 成绩排名

成绩排名 时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte 总提交 : 1809 测试通过 : 300 比赛描述 每学期考试结束,教务处老师都要对学生成绩进行一些统计。请你帮助教务处老师对学生成绩从高到低进行排名。成绩相同,排名序号相同,先后出现顺序与原始次序相同。输入第一行是一个正整数:测试

ysCover 726

Codeforces Round #249 (Div. 2) B. Pasha Maximizes(模拟)

B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha has a positive integer a without le

ysCover 702

Codeforces Round #338 (Div. 2) C. Running Track

C. Running Track time limit per test1 second memory limit per test512 megabytes inputstandard input outputstandard output A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet

ysCover 575
上一篇: HDU 5131 Song Jiang's rank list
下一篇: Codeforces 518D Ilya and Escalator
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值