UVa 10294(polya 翻转与旋转)
Arif in Dhaka(First Love Part 2)
Input: standard input
Output: standard output
Time Limit: 2 seconds
Our hero Arif is now in Dhaka (Look at problem 10244 – First Love 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;
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll; int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
ll ans1,ans2,pow[];
int main()
{
//printf("%d***\n",gcd(6,9));
int i,n,t;
while(~scanf("%d%d",&n,&t))
{
pow[]=;
ans1=;
for(i=;i<=n;i++)pow[i]=pow[i-]*t;
for(i=;i<n;i++)ans1+=pow[gcd(i,n)];//旋转
if(n&)ans2=n*pow[(n+)/];
else ans2=n/*(pow[n/+]+pow[n/]);//翻转
printf("%lld %lld\n",ans1/n,(ans1+ans2)//n);
}
}
UVa 10294(polya 翻转与旋转)的更多相关文章
- 项链与手镯Uva 10294——Polya定理
题意 项链和手镯都是由若干珠子串成的环形首饰,区别在于手环可以翻转,但项链不可以. 输入整数 $n$ 和 $t$,输出用 $t$ 中颜色 $n$ 颗珠子能制作成的项链和手镯的个数.($1\leq n ...
- Uva 10294 Polya
#include <bits/stdc++.h> using namespace std; typedef long long LL; int gcd(int a,int b) { ? a ...
- 【uva 10294】 Arif in Dhaka (First Love Part 2) (置换,burnside引理|polya定理)
题目来源:UVa 10294 Arif in Dhaka (First Love Part 2) 题意:n颗珠子t种颜色 求有多少种项链和手镯 项链不可以翻转 手镯可以翻转 [分析] 要开始学置换了. ...
- Arif in Dhaka (First Love Part 2) UVA - 10294(Polya定理)
这题和POJ-1286一样 题意: 给出t种颜色的n颗珠子 (每种颜色的珠子个数无限制,但总数必须是n), 求能制作出项链和手镯的个数 注意手镯可以翻转和旋转 而 项练只能旋转 解析: 注意Poly ...
- UVA 10294 项链与手镯 (置换)
Burnside引理:对于一个置换\(f\), 若一个着色方案\(s\)经过置换后不变,称\(s\)为\(f\)的不动点.将\(f\)的不动点数目记为\(C(f)\), 则可以证明等价类数目为\(C( ...
- UVa 10294 Arif in Dhaka (First Love Part 2)(置换)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397 [思路] Polya定理. 旋转:循环节为gcd(i,n) ...
- AS3.0 位图翻转、旋转
/* * * *-------------------------* * | *** 位图翻转.旋转 *** | * *-------------------------* * * 作 者:fengz ...
- 项目实战:Qt+Ffmpeg+OpenCV相机程序(打开摄像头、支持多种摄像头、分辨率调整、翻转、旋转、亮度调整、拍照、录像、回放图片、回放录像)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- UVa 10294 Arif in Dhaka (First Love Part 2) (Polya定理)
题意:给定 n 和 m 表示要制作一个项链和手镯,项链和手镯的区别就是手镯旋转和翻转都是相同的,而项链旋转都是相同的,而翻转是不同的,问你使用 n 个珠子和 m 种颜色可以制作多少种项链和手镯. 析: ...
随机推荐
- C# 前台和后台POST提交信息的实现方法
一.系统A(官网)与系统B(第三方支付平台)数据交换的方式 1.1 页面浏览器方式:系统A以构造Form表单的方式,通过系统A客户的浏览器重定向到系统B(向系统B发送请求),B系统完成交易后,将交易 ...
- 初识linux命令
1. type: 查看是外部命令/内部命令 外部命令 有存放地址信息 内部命令 is a shell builtin 2.file 查看文件的编码方式 file /sbin/ifconfig 编译执行 ...
- Xcode升级10.3后XIB文件报错
Xcode升级10.3后XiB文件包错,提示: Failed to find or create execution context for description '<IBCocoaTouch ...
- Hybrid平台
需求说明 离线包管理平台主要负责对需要接入Hybrid平台的应用进行管理,通过这个平台可以实现对应用的静态资源进行构建.发布.生成离线包,版本控制等,核心场景如下: 将需要做预加载的应用在平台上注册, ...
- 自动化运维--ansible(2)
问题一:如何在多台服务器中配置Web项目上线的所有环境 解答: 1.使用ansible配置nginx服务 在安装前了解rpm与yum的区别 rpm是压缩包安装依赖包需要自己手动安装,yum安装解决依 ...
- Promise【其他模式】
Promise @Slf4j public class Promise { /** * Promise Pattern[承诺]:承诺表示当前还未完成,但是会在将来完成的操作,用于实现异步计算. */ ...
- php5.4编译安装--nginx
1.下载源码包 wget 网址/源码包2.解压源码包 tar -zxvf 源码包3.创建一个安装目录 mkdir /usr/local/php4.进入解压后的目录中,初始化安装环境./configur ...
- 网易云课堂_C++程序设计入门(下)_第8单元:年年岁岁花相似– 运算符重载_第8单元 - 作业2:OJ编程 - 重载数组下标运算符
第8单元 - 作业2:OJ编程 - 重载数组下标运算符 查看帮助 返回 温馨提示: 1.本次作业属于Online Judge题目,提交后由系统即时判分. 2.学生可以在作业截止时间之前不限次数提 ...
- Golang http post error : http: ContentLength=355 with Body length 0
参考:https://stackoverflow.com/questions/31337891/net-http-http-contentlength-222-with-body-length-0 问 ...
- HTML真是好东西!
HTML真是好东西! 学习HTML已经两天了,别小看这两天哦,这短短的两天估计要比学校的四周还要长.不仅有教学,还有同学与老师之间的交流,最重要的是自己上机实践的过程.在这个过程中,不仅知道了在HTM ...