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 存在的问题进制错误 .. 思路不清晰 两个线段有交叉 并不是端点 ...
随机推荐
- X86控制寄存器和系统地址寄存器
80386控制寄存器和系统地址寄存器如下表所示.它们用于控制工作方式,控制分段管理机制及分页管理机制的实施. 控制寄存器 CRx BIT31 BIT30—BIT12 BIT11—BIT5 BIT4 B ...
- Centos 6.4搭建git服务器【转】
前阵子公司需要,让我搭个Git服务器,把之前用的SVN上代码迁移到git上去,所以就在阿里云主机上搭了一个,记录了下安装过程,留存文档以备查阅.本篇本章只涉及搭建部分的操作,更多git的使用可以参考文 ...
- 新版Java为什么要修改substring的实现
Java字符串的截取操作可以通过substring来完成.有意思的是,这个方法从jdk1.0开始,一直到1.6都没有变化,但到了1.7实现方式却发生了改变.你可能会认为之所以要对一个成熟且稳定的方法做 ...
- LeetCode312. Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...
- linux java环境变量设置
下载JRE或者JDK后解压,设置以下环境变量 JAVA_HOME=/home/zm/jdk1.8.0_181JRE_HOME=/home/zm/jdk1.8.0_181/jreCLASSPATH=.: ...
- mvc bundle的介绍及使用 转载自 http://www.ityouzi.com/archives/mvc-bundleconfig.html
Asp.Net MVC4 BundleConfig文件合并.压缩,网站优化加速 浏览器在向服务器发送请求的时候,请求的文件链接数量是有限制的,如果页面文件少就没有什么问题了,如果文件太多就会导致链接失 ...
- ref:一系列用于Fuzzing学习的资源汇总
ref:http://www.freebuf.com/articles/rookie/169413.html 一系列用于Fuzzing学习的资源汇总 secist2018-04-30共185833人围 ...
- 洛谷P2507 [SCOI2008]配对 [DP,贪心]
题目传送门 配对 题目描述 你有 n 个整数Ai和n 个整数Bi.你需要把它们配对,即每个Ai恰好对应一个Bp[i].要求所有配对的整数差的绝对值之和尽量小,但不允许两个相同的数配对.例如A={5,6 ...
- hibernate for循环执行添加操作出错问题
操作数据库使用hibernate框架 hibernate插入对象的时候,对于id唯一,数据库设置为自增的时候执行完操作后会将id赋予该对象 再次插入就会出现问题. 由于session缓存,得再研究下.
- PlayMaker布局技巧:预览GUI界面
PlayMaker布局技巧:预览GUI界面 PlayMaker提供丰富的动作用来构建界面.对于复杂界面,每次通过调试方式查看效果,会非常麻烦.这个时候,开发者可以考虑使用PlayMaker GUI ...