hdu1812 Polya定理

一直知道有这么个定理,但一直没理解,今天看了看书,差不多知道怎么用了,但证明还是完全不用会。。。

用polya定理解题其实就是确定置换及其循环节。这题显然就是8个置换,四个旋转(其中一个为不动。。)和四个翻转,其循环节数分别为①n*n②(n*n+3)/4③(n*n+1)/2④同2⑤n+(n*n-n)/2⑥同5⑦奇数时n+(n*n-n)/2偶数时n*n/2⑧同7

import java.io.*;

import java.math.BigInteger;

import java.util.*;

public class Main {

    public static Scanner getFileScanner(boolean isOnlineJudge) {

        if(isOnlineJudge) {

            return new Scanner(System.in);

        }

        File myFile = new File("data.in");

        FileInputStream myFileStream = null;

        try {

            myFileStream = new FileInputStream(myFile);

        } catch (FileNotFoundException e) {

        }

        Scanner cin = new Scanner(myFileStream);

        return cin;

    }

    public static void main(String[] args) {

        Scanner cin = getFileScanner(true);

        int N, C;

        int[] ar = new int[8];

        while(cin.hasNextInt()) {

            N = cin.nextInt();

            C = cin.nextInt();

            ar[0] = N * N;

            ar[1] = (N * N + 3) / 4;

            ar[2] = (N * N + 1) / 2;

            ar[3] = ar[1];

            ar[4] = N + (N * N - N) / 2;

            ar[5] = ar[4];

            if(N % 2 == 1) {

                ar[6] = N + (N * N - N) / 2;

            }else {

                ar[6] = N * N / 2;

            }

            ar[7] = ar[6];

            BigInteger ans = BigInteger.ZERO;

            BigInteger BC = BigInteger.valueOf(C);

            for(int i = 0; i < 8; i++) {

                ans = ans.add(BC.pow(ar[i]));

            }

            ans = ans.divide(BigInteger.valueOf(8));

            System.out.println(ans);

        }

    }

}

你可能感兴趣的:(HDU)