> 文档中心 > CF665B Shopping

CF665B Shopping


📋 个人简介

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

注:从今天开始:

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

📣Shopping

CF665B Shopping
CF665B Shopping
输入输出样例

输入 #12 2 53 4 1 2 51 53 1输出 #114

说明/提示
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

#includeusing 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;}

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