码迷,mamicode.com
首页 > 编程语言 > 详细

二分·归并排序之逆序对

时间:2015-04-02 16:39:09      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:public

http://hihocoder.com/contest/hiho39/problems


java.util.*;

Main {
    = ;

    mergSort(List<Long> a, l, r) {
        mid;
        (l < r) {
            mid = (l + r) / ;
            (a,l, mid);
            (a, mid + , r);
           List<Long> b1,b2;
            b1 = ArrayList<Long>(a.subList(l,mid+));
            b2 = ArrayList<Long>(a.subList(mid+,r+));
            List<Long>a1 = a.subList(l,r+);
            i1=,i2=,n1=b1.size(),n2=b2.size(),i=;
            (;i1<n1&&i2<n2;){
                ( b1.get(i1)<= b2.get(i2)){
                    a1.set(i,b1.get(i1));
                    i1++;
                    i++;
                }
                {
                    a1.set(i,b2.get(i2));
                    i++;
                    +=n1-i1;
                    i2++;

                }
            }
            ( i1< n1){
                a1.set(i,b1.get(i1));
                i++;
                i1++;
            }
            ( i2< n2){
                a1.set(i,b2.get(i2));
                i++;
                i2++;
            }
        }
    }

    main(String[] args) {
        List<Long> a;
        Scanner scanner = Scanner(System.);
        a= ArrayList();
        n1 = scanner.nextInt();

        (i = ; i < n1; i++) {
            a.add(scanner.nextLong());
        }
        (a, , n1 - );
        System..println();
}

}


本文出自 “8691404” 博客,请务必保留此出处http://8701404.blog.51cto.com/8691404/1627673

二分·归并排序之逆序对

标签:public

原文地址:http://8701404.blog.51cto.com/8691404/1627673

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!