CF665B Shopping

📋 个人简介

🎉大家好,我是3月份新人榜排名第三的 ༺Blog༒Hacker༻
💬支持我:点赞👍+收藏⭐️+留言📝
🌺格言:༺永做优质༒programmer༻

注:从今天开始:

我的更新时间主要在每周4、(5)、6.
更新内容会偏向英文题目
CFUVA为主
同时,感谢洛谷提供的翻译

📣Shopping

在这里插入图片描述
在这里插入图片描述
输入输出样例

输入 #1
2 2 5
3 4 1 2 5
1 5
3 1
输出 #1
14

说明/提示
Customer 11 wants the items 11 and 55 .

p o s ( 1 ) = 3 pos(1)=3 pos(1)=3, so the new positions are: [1,3,4,2,5]

p o s ( 5 ) = 5 pos(5)=5 pos(5)=5 , so the new positions are: [5,1,3,4,2]

Time taken for the first customer is 3+5=8

Customer 22 wants the items 33 and 11 .

p o s ( 3 ) = 3 pos(3)=3 pos(3)=3 , so the new positions are: [3,5,1,4,2]

p o s ( 1 ) = 3 pos(1)=3 pos(1)=3 , so the new positions are: [1,3,5,4,2]

Time taken for the second customer is 3+3=6

Total time is 8+6=14

Formally p o s ( x ) pos(x) pos(x) is the index of x in the current row.

💯AC CODE

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k,x,ans=0;
	int a[105];
	scanf("%d %d %d",&n,&m,&k);
	for (int i(1);i<=k;++i)
		scanf("%d",&a[i]);
	for (int i(1);i<=n*m;++i)
	{
		scanf("%d",&x);
		int j,l;
		for(j=1;j<=k;++j)
			if(a[j]==x)
				break;
		ans+=j;
		for(l=j; l>=2;--l)
			a[l]=a[l-1];
		a[1]=x;
	}
	printf("%d\n", ans);
	return 0;
}

🔮朋友们,点赞收藏是我更新的动力,明天再见,拜拜!!!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

༺Blog༒Hacker༻

您的鼓励将是我更新最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值