ACM: 计算交换次数的排序题 poj 22…
来源:互联网 发布:深圳阿里云大厦 编辑:程序博客网 时间:2024/05/19 20:59
Description
In this problem, you have toanalyze a particular sorting algorithm. The algorithm processes asequence of n distinct integers by swapping two adjacent sequenceelements until the sequence is sorted in ascending order. For theinput sequence
Ultra-QuickSort produces the output
Your task is to determine how many swap operations Ultra-QuickSortneeds to perform in order to sort a given input sequence.
Input
The input contains several test cases. Every test case beginswith a line that contains a single integer n <500,000 -- the length of the input sequence. Each of the thefollowing n lines contains a single integer 0 ≤ a[i] ≤ 999,999,999,the i-th input sequence element. Input is terminated by a sequenceof length n = 0. This sequence must not be processed.
Output
For every input sequence, your program prints a single linecontaining an integer number op, the minimum number of swapoperations necessary to sort the given input sequence.
Sample Input
5
9 1 0 5 4
3
1 2 3
0
Sample Output
6
0
题意: 将序列排序,从小到大.计算交换的次数,交换只可以和左右相邻的数字交换.
解题思路:
代码:
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 500003
int a[MAX];
int t[MAX];
int n;
long long merge_sort(int start,int end,int len)
{
}
int main()
{
//
}
- ACM: 计算交换次数的排序题 poj 22…
- ACM: 计算几何题 poj 2066
- ACM: 简单排序题 poj 2231 动动脑…
- ACM: 回文串 dp题 poj 1159 (滚动…
- ACM: 搜索题 poj 1…
- ACM: dp题 poj 1276 go on 动态规…
- ACM: 一题STL map题 poj 1002 (bt…
- ACM: poj 第50题 一题递推数论题 …
- ACM: 又是一题二分法题 poj 3122…
- ACM: dp动态规划题(难) poj 3267 …
- ACM: dp题(动态规划) poj 2151 (d…
- ACM: 树状DP 动态规划题 poj 1463 …
- ACM: 图论题 poj 2253 (poj上的dou…
- ACM: 图论题 poj 1789 (一次AC的水…
- ACM: n!末尾0的个数 数论题 poj 14…
- ACM: 线段树 poj 2482 煽情的情书!…
- ACM: 图论题 poj 2240 (floyd + ST…
- ACM: polay定理 数论题 poj 1286 …
- ACM: 深搜+剪枝 poj 1416
- ACM: 广搜题+gcd判断是否有解 poj…
- Mysqlite的基本用法
- ACM: 直接模拟题 poj 3087
- ACM: poj 3349 (学习hash多种方法.…
- ACM: 计算交换次数的排序题 poj 22…
- ACM: 模拟题 poj 2632 (开始做模拟…
- hdu_4714_Tree2cycle(树形DP)
- ACM: 最长子序 dp题 poj 2533
- ACM: 简单数塔题 dp题 poj 3176
- ACM: 最优解 dp题 poj 1260
- ACM: 最长升序和最长降序 dp题 poj…
- ACM: dp动态规划题(难) poj 3267 …
- ACM: dp题 poj 1276 go on 动态规…