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 ...
随机推荐
- 转:jsp内置对象中page与pageContext与el内置对象pageScope与pageContext区别
原文地址:jsp内置对象中page与pageContext与el内置对象pageScope与pageContext区别 首先说明一下jsp9大内置对象 (1)HttpSession类的session对 ...
- html 标签笔记
<一.HTML 基础结构> <html>________________________________<head><title>无标题文档</t ...
- opencv 替换图像中的一部分
首先选取图像中的Roi区域,然后对Roi区域进行赋值,那么原图像相应的区域也跟着变化了: dst = src.clone(); cv::Mat Roi(dst, cv::Rect(x, y, cut_ ...
- $(document).ready()方法和window.onload有什么区别?
①.window.onload 方法是在网页中所有的元素(包括元素的所有关联文件)完全加载到浏览器后才执行的: ②.$(document).ready()方法可以在DOM载入就绪时就对其进行操纵,并调 ...
- 用canvas画三角形的方法
<canvas id="favoriteRectangle" width="30" height="30"></canva ...
- JavaScript学习(六)
这里要注意: 1.num为NaN(因为str的开头不是数字) 2.NaN和NaN是不等的 3.NaN也是number.
- 【托业】托业(TOEIC)成绩 & 等级划分以及评分标准
托业(TOEIC)成绩 & 等级划分以及评分标准 TOEIC全称:Test of English for International Communication(国际交流英语测评) 已通行全球 ...
- java多线程和.net多线程区别与联系
在网上搜了好多,没有搜到这方面的内容,自己浅薄写点吧. 1..net和java的主线程和子线程,原理是类似的 (1).当子线程是前台线程时,主线程结束,子线程并未结束(还将继续运行,即进程未结束) ( ...
- gh-ost:不一样的在线表结构变更
简介: 2016年8月份,shlomi-noach在GitHub Engineering发文宣布gh-ost开源.gh-ost是什么?一个不依赖触发器实现的在线表结构变更工具. 对于数据库运维人员来说 ...
- JsonDataObjects基本演示
下载地址https://github.com/ahausladen/JsonDataObjects 执行程序截图 Json数据 { "name": "张三", ...