java 大数 快排 sort

import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
/**
 *
 * @author va
 */
public class Main
{
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        Scanner cin = new Scanner(System.in);
        BigInteger [] a = new BigInteger[20010];
        BigInteger m;
        int n;
        List<BigInteger> list = new LinkedList<BigInteger>();
        while (cin.hasNextInt())
        {
            n = cin.nextInt();
            if (n == 0)
            {
                break;
            }
            m = cin.nextBigInteger();
            list.clear();
            int i;
            for (i = 0; i < n; ++i)
            {
                a[i] = cin.nextBigInteger();
                list.add(a[i]);
            }
            Collections.sort(list);
            int res = 0;
            for (i = 0; i < n; ++i)
            {
                int high = n-1, low = i+1, mid = i;
                while (low <= high)
                {
                    mid = (low + high) / 2;
                    if (list.get(i).multiply(list.get(mid)).compareTo(m) == -1)
                    {
                        low = mid + 1;
                    }
                    else
                    {
                        high = mid - 1;
                    }
                }
                res += high - i;
            }
            System.out.println(res);
        }
    }
}

posted on 2010-03-26 13:26  ZAFU_VA  阅读(327)  评论(0编辑  收藏  举报

导航