BBuBBBlesort!
题目描述
Operation 1: choose 2 consecutive elements, then reverse the order of those elements.
Operation 2: choose 3 consecutive elements, then reverse the order of those elements.
Snuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.
Constraints
1≦N≦105
0≦Ai≦109
If i≠j, then Ai≠Aj.
All input values are integers.
输入
N
A1
:
AN
输出
样例输入
4
2
4
3
1
样例输出
1
提示
The given sequence can be sorted as follows:
First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.
Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.
In this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct data
{
int x=,p=;
};
bool cmp(data a,data b)
{
return a.x<b.x;
}
int main()
{ data a[];
data b[];
int l=,n,i;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&a[i].x);
a[i].p=i;
}
sort(a+,a+n+,cmp);
int ans=;
for(i=;i<=n;i++)
{
if(abs(a[i].p-i)%!=)
{
ans++;
}
}
printf("%d\n",ans/);
return ;
}
这代码是不是超级简单
当模拟真的很复杂但是想不出其他方法了,应该就是找规律
我们的最终目标是让从小到大排好
只要元素与它应该在的位置的距离是偶数,就一定不需要消耗方法1.
BBuBBBlesort!的更多相关文章
- [atARC102F]Revenge of BBuBBBlesort
定义以$i$为中心(交换$p_{i-1}$和$p_{i+1}$)的操作为操作$i$ 结论1:若执行过操作$i$,则之后任意时刻都无法执行操作$i-1$或操作$i+1$ 当执行操作$i$后,必然有$p_ ...
- atcoder题目合集(持续更新中)
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...
- 【Atcoder】ARC102 题解
C - Triangular Relationship 题解 枚举一个数%K的值然后统计另两个 代码 #include <bits/stdc++.h> #define enter putc ...
- 2018.09.02 Atcoder Regular Contest 102简要题解
比赛传送门 T1 Triangular Relationship 分析之后发现有两种情况: 1. n为奇数,那么所有数都是k的倍数. 2. n为偶数,那么所有数都是k/2的倍数. 然后就可以愉快A题了 ...
- AtCoder Grand Contest 003
AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. ...
- RE:从零开始的AGC被虐(到)生活(不能自理)
RE:从零开始的AGC被虐(到)生活(不能自理) 「一直注视着你,似近似远,总是触碰不到.」 --来自风平浪静的明天 AtCoder Grand Contest 001 B: Mysterious L ...
- AtCoder Grand Contest
一句话题解 QwQ主要是因为这篇文章写的有点长……有时候要找某一个题可能不是很好找,所以写了这个东西. 具体的题意.题解和代码可以再往下翻._(:з」∠)_ AGC 001 C:枚举中点/中边. D: ...
- AtCoder Regular Contest 102
AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...
- AtCoder AGC #3 Virtual Participation
Havana真好听qwq AB题就不写了 SB C.BBuBBBlesort! 有一个长度为$n$的数列 你每次可以用两种操作 1.交换两个相邻元素 2.交换两个隔且仅隔了一个的元素 求把数列排成有序 ...
随机推荐
- Ubuntu系统下QEMU环境搭建
(这篇文章是在搭建QEMU环境时,在网上找到了一些教程资料,并在实际操作中遇到的一些问题的整理) 下载Linux内核 下载内核有两种方法,一种是用git直接下载内核代码树,方便后面的内核开发.另一种是 ...
- ABP 切换mysql 数据库报错mysqlexception: incorrect string value: ‘\xe7\xae\x80\xe4\xbd\x93…’ for column display name
刚折腾了ABP框架,为了跨平台,将SQL Server数据库换成了MySQL数据库,ABP框架上支持多语言,中间被字符集折腾的够呛,翻了N个博客,最后终于在StackOverFlow 上找到了最终的解 ...
- 委托、Action、Func使用
参考 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...
- ZOJ 1454 dp
Employment Planning Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- android studio使用JDBC访问mysql数据库(Kotlin方法)
工具:mysql-connector-java-5.1.48.jar,mysql version 5.6.19,android studio内置模拟器 1.connection import java ...
- Node.js—第一个动态页面
话不多说 上代码 没有加什么处理也不严谨 只为效果 const http=require('http'), path=require('path'), fs=require('fs') //创建服务 ...
- Python D9 学习
Python 设置环境 当安装好Python 后 在计算机的属性里面 高级语言设置 环境变量. 环境变量里面的path 更改为Python的 树目录 可以从计算机直接下达命令 打开Pytho ...
- 28. docker swarm 容器编排简介
1.采用集群架构 集群架构包含节点和角色 docker 节点中 包含 worker 和 manager 两个角色 manager 相当于 swarm 集群的 大脑 是用来管理配置节点的 (避免单点故 ...
- openlayers基础用例
http://weilin.me/ol3-primer/ch03/03-01.html#http://weilin.me/ol3-primer/ //地址http://openlayers.org/ ...
- NodeJS框架一览
NodeJS 框架一览 Express 当你使用Node.js构建web应用程序时, Express通常被视为事实上的Web服务器.它的哲学(一个可以使用中间件包扩展的简约核心)是大多数Node.js ...