POJ 2299 - Ultra-QuickSort
来源:互联网 发布:php 上传文件进度 编辑:程序博客网 时间:2024/05/29 10:14
传送门POJ 2299 - Ultra-QuickSort
小白上的求逆序数的例题。。还是略有不懂。晚上再想想。。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;long long cnt, a[510000], t[510000];void MergeSort(long long *a, int x, int y, long long *t){ if (y - x > 1) { int m = x + (y - x) / 2; int p = x, q = m, i = x; MergeSort(a, x, m, t); MergeSort(a, m, y, t); while (p < m || q < y) { if (q >= y || (p < m && a[p] <= a[q])) t[i++] = a[p++]; else { t[i++] = a[q++]; cnt += m - p; } } for (i = x; i < y; i++) a[i] = t[i]; }}int main(){ //freopen("input.txt", "r", stdin); int n, i, j; while (scanf("%d", &n), n) { for (i = 0; i < n; i++) scanf("%lld", &a[i]); cnt = 0; MergeSort(a, 0, n, t); printf("%lld\n", cnt); } return 0;}
0 0
- POJ 2299 Ultra-QuickSort
- poj 2299 Ultra-QuickSort
- poj 2299 Ultra-QuickSort
- poj 2299 Ultra-QuickSort
- poj 2299 Ultra-QuickSort
- poj 2299Ultra-quicksort
- POJ-2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- poj 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 - Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- POJ 2299 Ultra-QuickSort
- 手势滑动删除ListView
- 14
- Protocol Buffer Basics: Java
- codeforce 6A
- 15
- POJ 2299 - Ultra-QuickSort
- 有意思的游戏:Google XSS Game
- 16
- 对非正确使用浮点型数据而导致项目BUG的问题探讨
- linux编程合并多个静态库.a为一个.a
- DATAGUARD 估算业务高峰redo传送网络的带宽
- JQuery日期插件datepicker的使用
- 17
- HDU1102_Constructing Roads(最小生成树)