题意(来自网络):

现在有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. IOS UIScrollView滚动到指定位置

    [mScrollView setContentOffset:CGPointMake(0,200) animated:YES];

  2. a completely rewritten architecture of Hadoop cluster

    https://www.ibm.com/developerworks/library/bd-yarn-intro/

  3. ​vmware虚拟机centos网络配置错误,执行/etc/init.d/network start 或 restart 提示Device eth0 has different MAC address than expected, ignoring

    vmware虚拟机centos网络配置错误,执行/etc/init.d/network start 或 restart 提示Device eth0 has different MAC address ...

  4. 解决express video 手机无法播放的问题

    http://stackoverflow.com/questions/24976123/streaming-a-video-file-to-an-html5-video-player-with-nod ...

  5. 基于 phantomjs 的自动化测试---(1)

    它主要靠js脚本来模拟操作一般流程是写代码写代码写代码open 某个 url监听 onload 事件事件完成后调用 sendEvent 之类的 api 去点击某个 DOM 元素所在 point触发交互 ...

  6. 基于springboot的Dubbo的常规总结

    1.引入jar包: <!-- Spring Boot Dubbo 依赖 --> <dependency> <groupId>com.alibaba.spring.b ...

  7. React Native 隐藏组件思路

    In your render function:{ this.state.showTheThing && <TextInput/>} Then just do: this. ...

  8. CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂

    题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second ...

  9. Canvas HTML5

    不支持的时候记得: <canvas id="stockGraph" width="150" height="150"> curr ...

  10. 「LOJ#10043」「一本通 2.2 例 1」剪花布条 (KMP

    题目描述 原题来自:HDU 2087 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? 输入格式 输入数据 ...