[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 ...
随机推荐
- NSIS笔记
1.IfFileExists IfFileExists D:\SA\test\testdirectory\*.* 0 +1 判断testdirectory是否是一个目录,若是,则执行接下来的第一行代码 ...
- 记录一次面试中的HTTP请求相关问题
1.HTTP中的状态码分别代表什么 比较基础,自行百度. 2.HTTP请求,响应头部content-length用来做什么的 答:Content-Length首部告诉浏览器报文中实体主体的大小.这 ...
- 逆袭之旅DAY20.XIA.循环结构
2018-07-16 19:53:47 while循环 do do...while循环 for 循环
- spring boot 打jar包
想必大家经常会出现以下报错信息 java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Fai ...
- linux:SSH最简单教程
1.简介 ssh是一种用于计算机之间的加密登录协议.用户从本地计算机用ssh协议登录另一台计算机就可以认为登录安全,中途截获密码也不会泄露. 2.原理 (1)用户发登录请求给远程主机 (2)远程主机发 ...
- java语句的控制流程
if(布尔表达式 ){ 程序执行语句1 }else { 程序执行语句2 } while(布尔表达式){ 程序执行语句 } do{ 程序执行语句 }while(布尔表达式); for(初始化语句,条件语 ...
- 打开和写入excel文件
一.使用win32读取excel内容 # -*- coding: utf-8 -*- from win32com import client as wc def open_excel(): excel ...
- 进程创建过程详解 CreateProcess
转载请您注明出处:http://www.cnblogs.com/lsh123/p/7405796.html 0x01 CreateProcessW CreateProcess的使用有ANSI版本的Cr ...
- Androi开发 ---Fragment片段布局案例
效果图: 1.MainActivity.java package com.example.android_activity; import android.app.Activity; import a ...
- 特殊权限set_uid
set_uid:该权限针对二进制可执行文件,使文件执行阶段具有文件所有者的权限.比如passwd这个命令就具有该权限.当普通用户执行passwd命令时,可以临时获得root权限,从而可以更改密码. 作 ...