博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa 10294(polya 翻转与旋转)
阅读量:6426 次
发布时间:2019-06-23

本文共 3534 字,大约阅读时间需要 11 分钟。

(First Love Part 2)

Input: standard input

Output: standard output

Time Limit: 2 seconds

 

Our hero Arif is now in Dhaka (Look at problem  if you want to know more about Arif, but that information is not necessary for this problem. In short, Arif is a brilliant programmer working at IBM) and he is looking for his first love. Days pass by but his destiny theory is not working anymore, which means that he is yet to meet his first love. He then decides to roam around Dhaka on a rickshaw (A slow vehicle pulled by human power), running DFS (by physical movement) and BFS (with his eyes) on every corner of the street and market places to increase his probability of reaching his goal. While roaming around Dhaka he discovers an interesting necklace shop. There he finds some interesting necklace/bracelet construction sets. He decides to buy some of them, but his programmer mind starts looking for other problems. He wants to find out how many different necklace/bracelet can be made with a certain construction set. You are requested to help him again. The following things are true for a necklace/bracelet construction set.

 

a)      All necklace/bracelet construction sets has a frame, which has N slots to place N beads.

b)      All the slots must be filled to make a necklace/bracelet.

c)      There are t types of beads in a set. N beads of each type are there in the box. So the total number of beads is tN (t multiplied by N), of which exactly N can be used at a time.

 

Fig: Different types of necklace for t=2 and different value of N

 

The figure above shows necklaces for some different values of N (Here, t is always 2). Now let’s turn out attentions to bracelets. A bracelet is a necklace that can be turned over (A junior programmer in Bangladesh says that wrist watch is a necklace (Boys!!! Don’t mind :-))). So for abracelet the following two arrangements are equivalent. Similarly, all other opposite orientation or mirror images are equivalent.

 

 

So, given the description of a necklace/bracelet construction set you will have to determine how many different necklace and bracelet can be formed with made with that set 

 

Input

The input file contains several lines of input. Each line contains  two positive integers N(0<N<51) and t(0<t<11) as described in the problem statement. Also note that within this input range inputs will be such that no final result will exceed 11 digits. Input is terminated by end of file.  

 

Output

For each line of input produce one line of output which contains two round numbers NN and NB separated by a single space, where NN is the number of total possible necklaces and NB is the number of total possible bracelets for the corresponding input set. 

 

Sample Input

5 2

5 3

5 4

5 5

 

Sample Output

8 8

51 39

208 136

629 377

 

旋转:每移动i颗珠子,循环节为gcd(i,n),故ans1=sum(t^gcd(i,n)),t为颜色种数;

 

翻转:奇:有n条对称轴,共(n+1)/2个循环节!  ans2=n*t^((n+1)/2)

   偶:1)穿过珠子有n/2条对称轴,有(n/2+1)个循环节!

     2)不穿过珠子也有n/2条对称轴,有n/2个循环节!  ans2=n/2*(t^(n/2+1)+t^(n/2))

 

根据polya定理:项链ans=ans/n;手镯ans=(ans1+ans2)/2n;

 

 

 

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 typedef long long ll; 7 8 int gcd(int a,int b) 9 {10 return b?gcd(b,a%b):a;11 }12 ll ans1,ans2,pow[100];13 int main()14 {15 //printf("%d***\n",gcd(6,9));16 int i,n,t;17 while(~scanf("%d%d",&n,&t))18 {19 pow[0]=1;20 ans1=0;21 for(i=1;i<=n;i++)pow[i]=pow[i-1]*t;22 for(i=0;i
View Code

 

 

 

 

 

 

转载于:https://www.cnblogs.com/skykill/p/3234179.html

你可能感兴趣的文章
《HTML与CSS入门经典(第8版)》——2.6 总结
查看>>
新手指南:在 Ubuntu 和 Fedora 上安装软件包
查看>>
在 CentOS7.0 上搭建 Chroot 的 Bind DNS 服务器
查看>>
大型网站的 HTTPS 实践(二):HTTPS 对性能的影响
查看>>
《Swift 权威指南》——第6章,第6.10节嵌套函数
查看>>
《自己动手做交互系统》——1.3 本章小结
查看>>
Mobile devices bundled with malware?
查看>>
《JavaScript面向对象精要》——1.5 访问属性
查看>>
《Python数据可视化编程实战》—— 第 1 章 准备工作环境
查看>>
Android应用性能优化最佳实践.1.1 Android Studio的优势
查看>>
《设计模式解析(第2版•修订版)》—第2章 2.2节什么是UML
查看>>
【直播】APP全量混淆和瘦身技术揭秘
查看>>
10个大坑,当你产品上架AppStore会遇到
查看>>
【shell 脚本】两种登录方式
查看>>
学习编程的方法
查看>>
升级linux自带的Python
查看>>
百度地图2.0瓦片地址获取(窗口内瓦片)
查看>>
我的友情链接
查看>>
.JDK1.6安装配置后的测试
查看>>
判断闰年的函数
查看>>