题目描述

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. C语言I作业博客07

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-1/homework/9935 我在这个课程的目 ...

  2. Spring原理系列一:Spring Bean的生命周期

    一.前言 在日常开发中,spring极大地简化了我们日常的开发工作.spring为我们管理好bean, 我们拿来就用.但是我们不应该只停留在使用层面,深究spring内部的原理,才能在使用时融汇贯通. ...

  3. js.console携程近期低价机票信息

    !function(){var city = {"SHA":"上海虹桥","PVG":"上海浦东","YIW& ...

  4. 吴裕雄--天生自然 JAVASCRIPT开发学习:弹窗

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> ...

  5. CPU构架和工作原理

    -- CPU -- -- CPU 由三部分组成:时钟:控制单元:算术逻辑单元 -- -- -- 时钟:对CPU内部操作与系统其他硬件进行同步: -- -- -- 控制单元:控制机器指令的执行顺序: - ...

  6. hdu 2072(字典树模板,set,map均可做)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=2072 lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词 ...

  7. 苹果下架2.5万赌博APP!一场净化风暴正在迅速成型

    当下智能手机发展得如火如荼,但对于大众来说,体验终究还是要落到包罗万千的APP上.APP身为智能手机的灵魂,全面渗入了大众的工作.生活.娱乐.学习等多个方面.每一个APP的背后,其实都在打开着一扇通往 ...

  8. 用eclipse运行算法第四版的BinarySearch

    import java.util.Arrays; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdIn; impo ...

  9. dp--最长上升子序列LIS

    1759:最长上升子序列 总时间限制:  2000ms 内存限制:  65536kB 描述 一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的.对 ...

  10. Linux 系统查看服务器SN序列号以及服务器型号

    1.单独查看服务器的序列号 [root@localhost ~]# dmidecode -t system | grep 'Serial Number' Serial Number: 2102310Y ...