zoj1873 Let it Bead

思路:polya裸题,如果是旋转,对于旋转i格的循环节长度len=lcm(i,n)/i,个数就是n/len=gcd(i,n);如果是翻转,奇数个点对称轴就是一个点一条边,那么循环节个数即n/2+1,

偶数个点有n/2条对称轴穿过两个点,循环节个数是n/2+1,n/2条对称轴穿过两条边,循环节个数就是n/2,然后直接套polya公式即可。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7
 8 int n,m;
 9
10 int gcd(int a,int b){
11     return b==0?a:gcd(b,a%b);
12 }
13
14 long long power(int a,int k){
15     if (k==0) return 1;
16     if (k==1) return a;
17     int x=power(a,k/2),ans=x*x;
18     if (k&1) ans*=a;
19     return ans;
20 }
21
22 int main(){
23     while (scanf("%d%d",&m,&n)!=EOF){
24         if (n==0 && m==0) break;
25         long long ans=0;
26         for (int i=1;i<=n;i++) ans+=power(m,gcd(n,i));
27         if (n&1) ans+=n*power(m,n/2+1);else ans+=n/2*power(m,n/2)+n/2*power(m,n/2+1);
28         printf("%lld\n",ans/(n*2));
29     }
30 } 

时间: 2024-10-20 14:01:49

zoj1873 Let it Bead的相关文章

珠排序Bead Sort

珠排序非常另类[地精也很另类],看完你就知道了,先介绍思路,再分解过程 这是它的英文论文 http://www.cs.auckland.ac.nz/~jaru003/research/publications/journals/beadsort.pdf 截图即从上边的论文里抓的屏 先了解一个概念,不然不容易理解,一个数字3用3个1来表示 一个数字9用9个1来表示,珠排序中的珠指的是每一个1,它把每一个1想像成一个珠子,这些珠子被串在一起,想像下算盘和糖葫芦 图1 上图1中的三个珠就表示数字3,两

poj 1975 Median Weight Bead(传递闭包 Floyd)

链接:poj 1975 题意:n个珠子,给定它们之间的重量关系,按重量排序,求确定肯定不排在中间的珠子的个数 分析:因为n为奇数,中间为(n+1)/2,对于某个珠子,若有至少有(n+1)/2个珠子比它重或轻,则它肯定不排在中间 可以将能不能确定的权值初始化为0,能确定重量关系的权值设为1 #include<stdio.h> #include<string.h> int a[110][110]; int main() { int T,n,m,i,j,k,d,x,sum; scanf(

【转】如何选择一个合适的磁珠BEAD

在产品数字电路EMC 设计过程中,我们常常会使用到磁珠,那么磁珠滤波地原理以及如何使用呢? 铁氧体材料是铁镁合金或铁镍合金,这种材料具有很高的导磁率,他可以是电感的线圈绕组之间在高频高阻的情况下产生的电容最小.铁氧体材料通常在高频情况下应用,因为在低频时他们主要程电感特性,使得线上的损耗很小.在高频情况下,他们主要呈电抗特性比并且随频率改变.实际应用中,铁氧体材料是作为射频电路的高频衰减器使用的.实际上,铁氧体较好的等效于电阻以及电感的并联,低频下电阻被电感短路,高频下电感阻抗变得相当高,以至于

TOJ-1317 Median Weight Bead

There are N beads which of the same shape and size, but with different weights. N is an odd number and the beads are labeled as 1, 2, ..., N. Your task is to find the bead whose weight is median (the ((N+1)/2)th among all beads). The following compar

poj 2049 Let it Bead(polya模板)

Description "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets.

POJ1975:Median Weight Bead(FLOYD)

Description There are N beads which of the same shape and size, but with different weights. N is an odd number and the beads are labeled as 1, 2, ..., N. Your task is to find the bead whose weight is median (the ((N+1)/2)th among all beads). The foll

NYOJ 280 LK的项链 &amp;&amp;POJ 2409 Let it Bead(polya 定理)

NYOJ 280 LK的项链  :click here POJ 2409 Let it Bead:click here 题意:一盒有红.蓝.绿三种颜色的珠子,每种颜色珠子的个数都大于24,现在LK想用这一盒珠子穿出一条项链,项链上的珠子个数为n(0<=n<=24),请你帮她计算一下一共可以用这一盒珠子可以穿出多少条不同的项链.通过旋转.翻转达到同一种状态的被认为是相同的项链. poj 上是c种颜色,s个珠子组成,数据比24小. 思路:今天刚接触到polya 定理: Polya定理:设G是n个对

POJ 2409 Let it Bead(Polya简单应用)

Let it Bead 大意:给你m种颜色,n个珠子串起来,旋转跟反转相同算相同,问有多少种不同的涂色组合方式. 思路:Polya的简单应用. 1 /************************************************************************* 2 > File Name: POJ2409.cpp 3 > Author: GLSilence 4 > Created Time: 2014年07月29日 星期二 22时56分58秒 5 **

TOJ-1341 Let it Bead

"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, ove