POJ 1286 解题报告

来源:互联网 发布:中国历史地名数据库 编辑:程序博客网 时间:2024/05/20 00:12

这道题是Polya题。我第一次接触到这个定理。看了别人的解题报告做的这道题:

看过的最好的解释:http://www.cnblogs.com/mcflurry/archive/2012/06/20/2556071.html

ACM中的数学问题:http://www.doc88.com/p-910707819004.html (莫名其妙的打不开50页之后的PPT)http://wenku.baidu.com/view/b1eb7cfdaef8941ea76e05f4.html

还是不清楚轮换个数(循环节)的求法,再遇到再深入吧。

这里,long long的表示空间比double大,因为我们没有小数部分。

thestoryofsnow1286Accepted208K0MSC++1317B

/* ID: thestor1 LANG: C++ TASK: poj1286 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;int gcd(int a, int b) {while (b != 0) {int r = a % b;a = b;b = r;}return a;}// Polya: http://wenku.baidu.com/view/b1eb7cfdaef8941ea76e05f4.html// S = (m^c_1 + m^c_2 + ... + m^c_G) / |G|// Analysis: http://www.cnblogs.com/mcflurry/archive/2012/06/20/2556071.htmlint main(){int n;while (scanf("%d", &n) > 0 && n >= 0) {// edge caseif (n == 0) {printf("0\n");continue;}long long ans = 0;// rotationfor (int i = 0; i < n; ++i) {ans += pow(3.0, (double)gcd(i, n));}// reflectionif (n & 1) {// if oddans += n * pow(3.0, (double) (n - 1) / 2 + 1);} else {// if even// the axis of symmetry is the line between a point and its opposite pointans += n / 2 * pow(3.0, (double) (n - 2) / 2 + 2);// the axis of symmetry is the line between the middle of two adjcent points and its oppositeans += n / 2 * pow(3.0, (double) n / 2);}printf("%lld\n", ans / (2 * n));}return 0; }




0 0
原创粉丝点击