题意(来自网络):

现在有k件商品,每个商品的位置已经告诉你了

现在有n个人,每个人有m个需求,每个需求就是要把第a[i][j]个物品拿到第一个位置来

他的代价是pos[a[i][j]]

问你所有代价是多少

思路:

就是每次+,每次调整,还有滚动数组这种不错欸~

#include <bits/stdc++.h>
using namespace std;
typedef __int64 LL;
int pos[2][110];
int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
int s=0;
for(int i=1;i<=k;i++)
scanf("%d",&pos[s][i]);
int ans=0,x;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&x);
for(int ii=1;ii<=k;ii++)
if(pos[s][ii]==x)
ans+=ii;
s=1-s;
int num=1;
pos[s][num++]=x;
for(int ii=1;ii<=k;ii++)
{
if(pos[1-s][ii]!=x)
pos[s][num++]=pos[1-s][ii];
}
}
}
printf("%d\n",ans);
return 0;
}

CodeForces 665B 【水-暴力】的更多相关文章

  1. Codeforces 734C [水][暴力][贪心]

    题意: 要生产n个物品,每个花费时间为x. 有两种魔法,每种最多使用1个. 其中第一种魔法可以使每个物品生产的花费时间变为ai,相应的花费是bi;第二种魔法可以减少ci个物品,相应的花费是di,并且保 ...

  2. 喵哈哈村的魔法考试 Round #1 (Div.2) 题解&源码(A.水+暴力,B.dp+栈)

    A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05   最后更新: 2017年2月21日 20:06   时间限制: 1000ms   内存限制: 128M 描述 传说喵哈哈村有三种神 ...

  3. Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)

    A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...

  4. Codeforces Round #407 (Div. 2)A B C 水 暴力 最大子序列和

    A. Anastasia and pebbles time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. codeforces 665B B. Shopping(水题)

    题目链接: B. Shopping time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  6. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  8. Codeforces Round #416 (Div. 2)A B C 水 暴力 dp

    A. Vladik and Courtesy time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces 913 二进制背包(柠檬水) 暴力贪心特殊背包(选题)

    A B C 给你N(N<=30)种水瓶每种水瓶有无限个 每个的体积是2^(i-1)价格是cost[i] 要求你花最少的钱弄出L体积的水 先从前到后扫一遍cost[i+1]=min(cost[i+ ...

随机推荐

  1. Redis(二)延迟队列

    1.目录 延迟队列 进一步优化 2.延迟队列 package com.redis; import java.lang.reflect.Type; import java.util.Set; impor ...

  2. Linux环境下安装Tomcat

    一.准备安装的tar包 1.将安装包放在服务器上:apache-tomcat-7.0.81.tar.gz 2.将安装包解压:tar -zxvf apache-tomcat-7.0.81.tar.gz ...

  3. SecureCRT中使用VBs脚本自动telnet登陆

    查看SecureCRT帮助文档: Help-> Help Topics->Scripting -> Script Objects Reference -> Session Ob ...

  4. 谷歌浏览器使用SelectorGadget和Xpath Helper获取xpath和css path

    在上篇文章里,介绍了如何在火狐浏览器中获取网页元素的xpath和css path. 这篇文章将介绍,在谷歌浏览器中使用SelectorGadget和Xpath Helper实现同样功能. 这两个谷歌浏 ...

  5. appium(10)-iOS predictate

    iOS predictate It is worth looking at ’-ios uiautomation’ search strategy with Predicates. UIAutomat ...

  6. dij+堆优化

    写这个dij+堆优化的原因是有些地方卡SPFA,只能搞这个: 香甜的奶油: #include<iostream> #include<cstdio> #include<cs ...

  7. 关于oracle批量插入数据遇到的问题

    截取部分日志信息: 2015-09-01 14:48:47,132 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReade ...

  8. CSU1808 地铁 —— dijkstra变形

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 题解:由于中转线路需要花费一定的时间,所以一般的以顶点为研究对象的dijkst ...

  9. HDU1873 看病要排队 —— 优先队列(STL)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 题解: 题目已经说出了解题方法:优先队列.但是之前没有学过优先队列,而且这题还是在现场赛做的.由 ...

  10. java编程思想-基础

    interface: 方法默认为public:成员变量默认 static and final 对象数组的定义:理解? 多接口继承:可以多个接口,但只有一个具体类,具体类在前面 自:多接口继承时,来自不 ...