题目描述

Snuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1≦i≦N) element of the sequence is ai. The elements are pairwise distinct. He is sorting this sequence in increasing order. With supernatural power, he can perform the following two operations on the sequence in any order:

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.

输入

The input is given from Standard Input in the following format:

N
A1
:
AN

输出

Print the minimum number of times Operation 1 that Snuke has to perform.

样例输入

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!的更多相关文章

  1. [atARC102F]Revenge of BBuBBBlesort

    定义以$i$为中心(交换$p_{i-1}$和$p_{i+1}$)的操作为操作$i$ 结论1:若执行过操作$i$,则之后任意时刻都无法执行操作$i-1$或操作$i+1$ 当执行操作$i$后,必然有$p_ ...

  2. atcoder题目合集(持续更新中)

    Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...

  3. 【Atcoder】ARC102 题解

    C - Triangular Relationship 题解 枚举一个数%K的值然后统计另两个 代码 #include <bits/stdc++.h> #define enter putc ...

  4. 2018.09.02 Atcoder Regular Contest 102简要题解

    比赛传送门 T1 Triangular Relationship 分析之后发现有两种情况: 1. n为奇数,那么所有数都是k的倍数. 2. n为偶数,那么所有数都是k/2的倍数. 然后就可以愉快A题了 ...

  5. AtCoder Grand Contest 003

    AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. ...

  6. RE:从零开始的AGC被虐(到)生活(不能自理)

    RE:从零开始的AGC被虐(到)生活(不能自理) 「一直注视着你,似近似远,总是触碰不到.」 --来自风平浪静的明天 AtCoder Grand Contest 001 B: Mysterious L ...

  7. AtCoder Grand Contest

    一句话题解 QwQ主要是因为这篇文章写的有点长……有时候要找某一个题可能不是很好找,所以写了这个东西. 具体的题意.题解和代码可以再往下翻._(:з」∠)_ AGC 001 C:枚举中点/中边. D: ...

  8. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

  9. AtCoder AGC #3 Virtual Participation

    Havana真好听qwq AB题就不写了 SB C.BBuBBBlesort! 有一个长度为$n$的数列 你每次可以用两种操作 1.交换两个相邻元素 2.交换两个隔且仅隔了一个的元素 求把数列排成有序 ...

随机推荐

  1. HashMap实现原理(jdk1.7),源码分析

    HashMap实现原理(jdk1.7),源码分析 ​ HashMap是一个用来存储Key-Value键值对的集合,每一个键值对都是一个Entry对象,这些Entry被以某种方式分散在一个数组中,这个数 ...

  2. E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)

    "Duel!" Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty ha ...

  3. py02_04:三元运算法

    a if a > b else c     #  a>b 成立,则为真,如果a>b为假,则返回c

  4. JAVA 算法练习(二)

    和上次一样,虽说用 java 语言,但有 c 的基础一样可以看懂哦. 机器人走方格问题Ⅰ 题目概述 有一个XxY的网格,一个机器人只能走格点且只能向右或向下走,要从左上角走到右下角.请设计一个算法,计 ...

  5. MongoDB_走一波

    Mongodb 一.mongodb的介绍 mongodb的优势 易扩展:NoSQL数据库种类繁多,但是一个共同的特定就是去掉关系数据库的关系型特性.数据之间无关系,这样非常容易扩展 大数据,高性能:N ...

  6. CSS3新属性:在网站中使用访客电脑里没有安装的字体

    CSS的font-family属性使网页可以使用客户电脑里的字体,从而得到多姿多彩的WEB页面,但当客户端没有你想要使用的字体时怎么办呢?我们总不能让每个访问者都去安装一个字体吧?事实上,这是可以的! ...

  7. redis基本指令

    1.键值相关命令       keys * 取出当前所有的key       exists name 查看n是否有name这个key       del name 删除key name       e ...

  8. bfs--奇怪的电梯P1135

    计院有一个bug电梯,可能是hyk造的,很多bug,电梯只有两个按钮,“上”和“下”,电梯每层都可以停,每层都有一个数字Ki(0<=Ki<=n),当你在一层楼,你按“上”键会到1+K1层, ...

  9. ALAsset

    ALAsset类代表相册中的每个资源文件,可以通过它获取资源文件的相关信息还能修改和新建资源文件,ALAssetRepresentation类代表相册中每个资源文件的详细信息,可以通过它获取资源的大小 ...

  10. nvm安装教程

    nvm是一个nodejs的版本管理工具 默认安装位置  C:\Users\userName\AppData\Roaming\nvm x   1 C:\Users\userName\AppData\Ro ...