[Codeforces Round #492 (Div. 1) ][B. Suit and Tie]
http://codeforces.com/problemset/problem/995/B
题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的数字相邻的最少交换次数.(n<100)
题目分析:n的数据范围特别小,所以只需要想到合理的(贪心)移动方式直接模拟即可,可以从左往右进行遍历,遍历到每个位置时,都把在这个位置之后且与这个数字相同的数字移动到它的旁边直接模拟即可(之所以正确是因为这样移动会使两个相同元素之间的元素都往后移动一次,由于是从左到右遍历,所以这些元素往后移动会减少以后移动的次数).
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
int qwq[],a[];
int main(){
//freopen("in.txt","r",stdin);
int n;
cin>>n;
for(int i=;i<*n;i++){
scanf("%d",&qwq[i]);
a[qwq[i]]=i;
}
int ans=;
for(int i=;i<*n;i++){
if(a[qwq[i]]>i+){
for(int j=i+;j<a[qwq[i]];j++){
if(a[qwq[j]]>a[qwq[i]])ans--;
}
ans+=a[qwq[i]]-i-;
}
}
cout << ans << endl;
return ;
}
[Codeforces Round #492 (Div. 1) ][B. Suit and Tie]的更多相关文章
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #492 (Div. 2)
A. /* 从大往小依次除 */ #include<cstdio> #include<algorithm> #include<cstring> #include&l ...
- Codeforces Round #492 (Div. 2) [Thanks, uDebug!]
这次的题好奇怪哦... C - Tesla 思路:先把跟停车位相邻的车停进去,然后开始转圈... #include<bits/stdc++.h> #define LL long long ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- Maven常见jar包依赖
<!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactI ...
- CAD绘制扶手5.6
用PL命令绘制出扶手的位置,如图 , “楼梯其他”“添加扶手”选择这条线,扶手宽度60,高度900,中间对齐.生成如图: 三维:
- 逆袭之旅.DAY07东软实训..封装~继承~抽象~final
2018年7月3日.逆袭之旅DAY07 package day0703.exam1; /** * 狗狗类 使用权限修饰符private和public进行封装 * @author Administrat ...
- learning ddr mode reigster set command cycle time tMRD and tMOD
tMRD: tMOD:
- python 学习 map /reduce
python 内建了map()和reduce()函数 map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. ...
- SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
题目描述 对于如下表actor,其对应的数据为: actor_id first_name last_name last_update 1 PENELOPE GUINESS ...
- SQL-16 统计出当前各个title类型对应的员工当前薪水对应的平均工资。结果给出title以及平均工资avg。
题目描述 统计出当前各个title类型对应的员工当前薪水对应的平均工资.结果给出title以及平均工资avg.CREATE TABLE `salaries` (`emp_no` int(11) NOT ...
- java中Calendar类
1.测试代码: package com; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util. ...
- 一、TCP扫描技术
一.TCP扫描技术 常用的端口扫描技术有很多种,如 TCP connect() 扫描 .TCP SYN 扫描.TCP FIN 扫描 等,网络上也有很多文章专门介绍,比如 :http://www.ant ...
- nginx——ngx_http_gzip_module
文件压缩 Syntax: gzip on | off; Default: gzip off; Context: http, server, location, if in location Synta ...