Java

class tool
{
    static void swap(int a[],int x,int y)
    {
        int t=a[x];
        a[x]=a[y];
        a[y]=t;
    }
    static long qpow(long x,long y)
    {
        long mod=1000000007,res=1;
        for(x%=mod;y!=0;y>>=1,x=x*x%mod)
            if((y&1)!=0)res=res*x%mod;
        return res;
    }
    static void sort(int a[],int l,int r)
    {
        if(l>=r)return;
        Random rd=new Random();
        int x=rd.nextInt(r)%(r-l+1)+l;
        swap(a,x,r);
        int i=l,j=r-1;
        while(true)
        {
            while(a[i]<a[r])i++;
            while(a[j]>a[r])j--;
            if(j<i)break;
            swap(a,i++,j--);
        }
        swap(a,i,r);
        if(l<i-1)sort(a,l,i-1);
        if(i<r)sort(a,i,r);
    }
};
static class InputReader
    {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream)
        {
            reader=new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer=null;
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try
                {
                    tokenizer=new StringTokenizer(reader.readLine());
                }
                catch(IOException e)
                {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容