Codeforces Round #324 (Div. 2) E
这题贪心,考虑先放第一个,然后从第一个数在p中的位置, 不断的往前走,和在他后面的那些数组进行交换,因为这样交换可以提高最大的效率,就是说你花费了1但是使得两个点都朝他的木匾节点减少了1
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
const int maxn=;
int A[maxn],B[maxn],idx[maxn],D[maxn];
pair<int,int>P[maxn];
int main()
{
int N;
while(scanf("%d",&N)==)
{
for(int i=; i<=N; i++)
{
scanf("%d",&B[i]);
idx[B[i]]=i;
}
for(int i=; i<=N; i++)
{
scanf("%d",&D[i]);
A[D[i]]=i;
}
int cost=,num=;
for(int i=; i<=N; i++)
{
int d=D[i];
if(d==B[i])continue;
int Loc=idx[d];
for(int i=idx[d]-; i>;i--)
{
int d1=B[i];
if( idx[d] == A[d] )break;
if(A[d1]>=Loc){
cost+=abs(idx[d1]-idx[d]);
swap(idx[d1],idx[d]);
P[num++]=make_pair(idx[d1],idx[d]);
swap(B[i],B[Loc]);
Loc=i;
}
}
}
printf("%d\n",cost);
printf("%d\n",num);
for(int i= ; i<num; i++)
printf("%d %d\n",P[i].first,P[i].second);
}
return ;
}
Codeforces Round #324 (Div. 2) E的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...
- Codeforces Round #324 (Div. 2) A. Olesya and Rodion 水题
A. Olesya and Rodion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/p ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #324 (Div. 2) Dima and Lisa 哥德巴赫猜想
原题链接:http://codeforces.com/contest/584/problem/D 题意: 给你一个奇数,让你寻找三个以内素数,使得和为这个奇数. 题解: 这题嘛...瞎比搞搞就好,首先 ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
随机推荐
- SQL join的介绍
学员表 SELECT * FROM tb_address; SELECT * FROM tb_student 1.JOIN关联两个表数据,将匹配数据展示,数据无匹配值则不展示 注释:INNER JOI ...
- 如何在安装node\npm\cnpm
1.安装node.js node.js的官方地址为:https://nodejs.org/en/download/. 根据windows版本后,选择要下载的安装包,下载完毕,按照windows一般应用 ...
- Jenkins send build artifacts over ssh配置
配置jenkins远程部署的时候遇到的配置问题: 首先在系统设置-系统设置-Publish over SSH-SSH Server中配置服务器信息 配置完成后可以点击Test Configuratio ...
- 微信小程序tabbar设置样式在哪里改
微信小程序tabbar通俗点说就是底部导航,我们一般会配置相关的菜单,方便读者快速导航.tabbar是在项目根目录中的配置文件 app.json 中进行设置:如果小程序是一个多 tab 应用(客户端窗 ...
- MySQL数据库的权限问题操作及基本增删改查操作
前面我们讲了mysql的基本内容,现在我们详细的了解一下mysql中的具体操作. what's the SQl SQL(Structured Query Language 即结构化查询语言) SQL语 ...
- ssh工具自动化命令
SCP命令 scp [options] SRC... DEST/ 两种方式: scp [options] [user@]host:/sourcefile /destpath scp [options ...
- 小睿开始呼叫用户,然后FS怎么跟用户交互的整个流程原理
学习从小睿开始呼叫用户,然后FS怎么跟用户交互的整个流程原理; 1.小睿向欣方新发起呼叫请求; 2.欣方新可以通过线路发起SIP协议请求,来呼叫用户; 3.当用户接通后,将建立 ...
- CentOS7.0+Zend Guard Loader for PHP 5.6环境搭建
本文是在centos7.0环境下搭建的, 由于我的php是5.6版本的, 所以需要去下载对应的Zend Guard Loader. 下载地址: http://www.zend.com/en/produ ...
- Spark SQL读取Oracle的number类型的数据时精度丢失问题
Spark SQL读取数据Oracle的数据时,发现number类型的字段在读取的时候精度丢失了,使用的spark版本是Spark2.1.0的版本,竟然最后经过排查和网上查资料发现是一个bug.在Sp ...
- Py中reshape中的-1表示什么【转载】
转自:https://blog.csdn.net/weixin_39449570/article/details/78619196 1.新数组的shape属性应该要与原来数组的一致,即新数组元素数量与 ...