zoukankan      html  css  js  c++  java
  • UVa 10294 Arif in Dhaka (First Love Part 2)(置换)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397

    【思路】

           Polya定理。

           旋转:循环节为gcd(i,n),i为偏移距离。

           翻转:当n为偶数时,对称轴过点时循环节为n/2+1有n/2个,不过点时循环节为n/2有n/2个。

           使用polya定理进行计数即可。

    【代码】

     1 #include<cstdio>
     2 using namespace std;
     3 
     4 typedef long long LL;
     5 const int N = 50+5;
     6 
     7 LL pow[N];
     8 int n,t;
     9 
    10 int gcd(int a,int b) {
    11     return (!b)? a:gcd(b,a%b);
    12 }
    13 
    14 int main() {
    15     pow[0]=1;
    16     while(scanf("%d%d",&n,&t)==2) {
    17         for(int i=1;i<=n;i++) pow[i]=t*pow[i-1];
    18         LL a=0;
    19         for(int i=0;i<n;i++) a += pow[gcd(i,n)];
    20         LL b=0;
    21         if(n&1) b=n*pow[(n+1)/2];
    22         else b=n/2*(pow[n/2+1]+pow[n/2]);
    23         printf("%lld %lld
    ",a/n,(a+b)/2/n);
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    MySQL(后篇)
    数据库
    Ajax
    JQuery
    BOM & DOM
    CSS
    HTML
    Python之IO多路复用学习
    vue-router小记
    js中运算符的优先级
  • 原文地址:https://www.cnblogs.com/lidaxin/p/5128603.html
Copyright © 2011-2022 走看看