codeforces 518 C. Anya and Smartphone

DeepSeek在教育平台考试作弊检测中的作用规划方案.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;
}





高速PCB设计中的信号完整性挑战:回损、插损与串扰的深度解析 本文深度解析了高速PCB设计中信号完整性面临的三大核心挑战:回波损耗、插入损耗与串扰。文章以工程师视角,结合实战案例,阐述了回损、插损与串扰的产生机理、关键影响因素及具体优化策略,如阻抗匹配、材料选择、3W原则等,旨在帮助工程师有效应对高速信号传输中的信号衰减、反射与干扰问题,确保设计可靠性。 阅读详情

相关推荐

高速SerDes均衡技术解析

均衡技术是高速SerDes链路中补偿信道损耗和失真的核心技术,通过FFE、CTLE和DFE三种主要方法对抗码间干扰(ISI)。FFE在发射端预补偿前光标干扰,CTLE通过提升高频增益补偿信道损耗,DFE则精准消除后光标干扰。三种技术各具优势:FFE实现简单且不放大噪声,CTLE功耗低易于集成,DFE能自适应调整且保持信噪比。这些技术协同工作可有效提升系统传输速率和可靠性。

一只豌豆象的博客 1968

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都是一种感动 595

Windows Server 2022域控环境下的MDT部署工具安装与配置避坑指南

本文详细介绍了在Windows Server 2022域控环境中安装和配置MDT(Microsoft Deployment Toolkit)的全流程,包括ADK与Windows PE的精准安装、MDT高级配置、部署工作流构建及性能优化技巧。通过实战指南帮助IT管理员实现自动化系统部署,提升企业IT运维效率,特别适用于需要静默下发系统的大规模部署场景。

weixin_28481133的博客 449

CodeForces - 518C Anya and Smartphone(链表)

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

小G的ACM之路 1176

USB2.0基础知识总结

目录 1、协议层: 1.1、域分类 1.2 、USB传输方式: 1、协议层: 域和包定义:包是一次传输的单位,每个包由多个域组成; USB中是按照LSB进行字节传输; 1.1、域分类 1.1.1: 同步域(SYNC field) 所有的包都开始于同步域,在低速和全速通信中SYNC field用7个0和1个1来表示。 由于USB2.0使用了NRZI编码(0用翻转来表示,1用不翻转表示),所以00000001就是上图那样。 ...

qq_32938605的博客 4419

Spring AI + RAG 构建电商智能客服:从 PDF 文档解析到精准问答的全链路实战

核心框架:向量数据库:- PostgreSQL + pgvector (生产推荐)- Redis Stack (轻量级方案)- ChromaDB (快速原型)文档解析:- Apache PDFBox: PDF 文本提取- Spring AI Document Readers: 结构化解析大模型:- 阿里云百炼 (DashScope)- 本地部署:Qwen/ChatGLM/*** 电商领域实体*/@Data@Builder@ToString/*** 商品类型。

一起修行,不孤单。这里有编程语言、开发工具、学习方法论和踩坑笔记。用简单的话说复杂的事,陪你从小白到进阶。周更干货,欢迎一起成长! 394

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 596

MATLAB/Simulink与ThingSpeak集成:打通物联网数据与工业算法仿真的闭环

在工业算法开发与控制系统设计中,模型仿真与真实世界数据的脱节是常见的工程挑战。其核心原理在于构建一个双向数据流闭环,将虚拟的仿真模型与物理世界的传感器网络连接起来。这一技术方案的核心价值在于大幅缩短算法迭代周期,实现数据驱动的设计与验证。典型的应用场景包括数字孪生构建、预测性维护和硬件在环(HIL)测试的云端化。通过将MATLAB/Simulink这一强大的模型化设计环境,与ThingSpeak物联网云平台进行深度集成,工程师能够轻松地将实时或历史的物联网数据流直接注入仿真模型作为输入,同时将仿真结果实时回

weixin_34220179的博客 475

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的博客 342

Elsevier投稿实战:从ESWA模板到录用通知的全流程拆解

本文详细拆解了Elsevier旗下期刊ESWA(Expert Systems With Applications)的投稿全流程,从模板选择、投稿系统操作到审稿意见回复和录用后注意事项。重点分享了单栏LaTeX模板调整、APA文献格式处理、Highlights撰写技巧等实战经验,帮助研究者高效完成投稿并提升录用概率。

weixin_32715349的博客 264

【Zephyr存储专题】18_从零教你开发MMC卡驱动(寄存器篇)

本文深入探讨eMMC/SDMMC控制器硬件结构及寄存器配置,为驱动开发提供技术参考。重点解析eMMC内部结构(Flash阵列、控制器、接口)和SDMMC关键寄存器(控制寄存器CR、命令寄存器CMDR等),详细说明各寄存器功能位域,包括时钟控制、DMA配置、命令传输等核心操作。文章还介绍了数据线配置和多线并行传输机制,为开发者实现卡驱动和文件系统适配提供实用指导。

zero的博客 74

CodeForces - 518C Anya and Smartphone

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

DT2131 606

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

noj 1046 第K回文数

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

ysCover 1225

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

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 1132

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 945

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 881

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

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

ysCover 871

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 793

noj 1005 多项式加法

模拟 noj

ysCover 750

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 728

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 705

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 577
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址