Educational Codeforces Round 12 B. Shopping 暴力
B. Shopping
题目连接:
http://www.codeforces.com/contest/665/problem/B
Description
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≤ j ≤ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer.
When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating.
Your task is to calculate the total time it takes for Ayush to process all the orders.
You can assume that the market has endless stock.
Input
The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k.
Each of the next n lines contains m distinct integers aij (1 ≤ aij ≤ k) — the order of the i-th person.
Output
Print the only integer t — the total time needed for Ayush to process all the orders.
Sample Input
2 2 5
3 4 1 2 5
1 5
3 1
Sample Output
14
Hint
题意
现在有k件商品,每个商品的位置已经告诉你了
现在有n个人,每个人有m个需求,每个需求就是要把第a[i][j]个物品拿到第一个位置来
他的代价是pos[a[i][j]]
问你所有代价是多少
题解:
数据范围太小了,所以直接暴力就好了~
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
int a[maxn],b[maxn],t=0;
int main()
{
int ans = 0;
int n,m,k;
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++)
{
int x;scanf("%d",&x);
int pos = 0;
for(int j=1;j<=k;j++)
if(x==a[j])pos=j;
ans+=pos;
b[1]=a[pos];
t=2;
for(int j=1;j<=k;j++)
if(j!=pos)b[t++]=a[j];
for(int j=1;j<=k;j++)
a[j]=b[j];
}
cout<<ans<<endl;
}
Educational Codeforces Round 12 B. Shopping 暴力的更多相关文章
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 字典树
E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...
- Educational Codeforces Round 12 A. Buses Between Cities 水题
A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...
- Educational Codeforces Round 12 B C题、
B. Shopping 题意:n个顾客,每个顾客要买m个物品,商场总共有k个物品,看hint就只知道pos(x)怎么算了,对于每一个Aij在k个物品中找到Aij的位置.然后加上这个位置对于的数值,然后 ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- Educational Codeforces Round 12 D. Simple Subset 最大团
D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...
- Educational Codeforces Round 12 C. Simple Strings 贪心
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...
- Educational Codeforces Round 12 E Beautiful Subarrays
先转换成异或前缀和,变成询问两个数异或≥k的方案数. 分治然后Trie树即可. #include<cstdio> #include<algorithm> #define N 1 ...
- Educational Codeforces Round 12补题 经典题 再次爆零
发生了好多事情 再加上昨晚教育场的爆零 ..真的烦 题目链接 A题经典题 这个题我一开始推公式wa 其实一看到数据范围 就算遍历也OK 存在的问题进制错误 .. 思路不清晰 两个线段有交叉 并不是端点 ...
随机推荐
- 17 - 路径操作-shutil模块
目录 1 路径操作 1.1 os.path模块 1.2 pathlib模块 1.2.1 目录操作 1.2.2 文件操作 1.3 os 模块 2 shutil模块 2.1 copy复制 2.2 rm删除 ...
- 64_p8
python2-cotyledon-tests-1.6.7-2.fc26.noarch.rpm 12-Feb-2017 10:28 23182 python2-couchdb-1.0-6.fc26.n ...
- 【SSH项目实战】脚本密钥的批量分发与执行【转】
[TOC] 前言 <项目实战>系列为<linux实战教学笔记>第二阶段内容的同步教学配套实战练习,每个项目循序衔接最终将组成<Linux实战教学笔记>第二阶段核心教 ...
- UVA题解二
UVA题解二 UVA 110 题目描述:输出一个Pascal程序,该程序能读入不多于\(8\)个数,并输出从小到大排好序后的数.注意:该程序只能用读入语句,输出语句,if语句. solution 模仿 ...
- rds 与mysql 进行主从同步
.rds上默认会有server-****,只需要配置从数据库: .从数据库的配置流程: .[mysqld] log-bin = mysql-bin-changelog #要和主库中的名字一样 rela ...
- Linux文档时间戳查看和修改——stat
查看文件时间戳命令:stat awk.txtFile: `awk.txt'Size: 20 Blocks: 8 IO Block: 4096 regular fileDevice: 801h/2 ...
- 四、ansible主机组定义
1.打开hosts文件 vim /etc/ansible/hosts 2.定义一个主机组 [web-server] 192.168.1.1 3.定义多个组(继承) [web:children] web ...
- C#窗口矩形区域着色
C#写的一个GUI窗口,有几百个矩形区域.每个矩形区域的颜色随时都可能改变,并且多次改变. 我放弃使用label绘制矩形,因为效果不好.拖控件的界面使用power packs中的rectanglesh ...
- 全栈Python 必备库
强大的库: 转自:微信公众号 Python最棒的地方之一,就是大量的第三方库,覆盖之广,令人惊叹.Python 库有一个缺陷就是默认会进行全局安装.为了使每个项目都有一个独立的环境,需要使用工具vir ...
- Jenkins+Ant+SVN+Jmeter实现持续集成
一.什么是持续集成? 待补充 二.说明: 本次框架介绍中不涉及到介绍框架的构建过程,介绍如何构建环境详细的构建见前篇文章: jmeter+Jenkins持续集成(邮件通知) Jmeter+Jenki ...