码迷,mamicode.com
首页 > 其他好文 > 详细

10294 - Arif in Dhaka (First Love Part 2) (数论置换)

时间:2014-07-18 15:12:41      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   art   io   

UVA 10294 - Arif in Dhaka (First Love Part 2)

题目链接

题意:给定n个珠子,t种颜色, 问能组成几个项链和手镯(手镯能翻转,项链不能)

思路:利用Burnside求解,推理出旋转的循环个数是gcd(i, n),翻转的分为奇偶情况考虑

代码:

#include <stdio.h>
#include <string.h>

const int N = 30;
int t, next[N], vis[N], num[N];
char str[N];

bool judge() {
	for (int i = 2; i <= 26; i += 2)
		if (num[i] % 2) return false;
	return true;
}

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%s", str);
		for (int i = 0; i < 26; i++)
			next[i] = str[i] - 'A';
		memset(vis, 0, sizeof(vis));
		memset(num, 0, sizeof(num));
		for (int i = 0; i < 26; i++) {
			if (!vis[i]) {
				vis[i] = 1;
				int t = next[i];
				int cnt = 1;
				while (!vis[t]) {
					vis[t] = 1;
					t = next[t];
					cnt++;
    			}
    			num[cnt]++;
   			}
  		}
  		printf("%s\n", judge()?"Yes":"No");
	}
	return 0;
}


10294 - Arif in Dhaka (First Love Part 2) (数论置换),布布扣,bubuko.com

10294 - Arif in Dhaka (First Love Part 2) (数论置换)

标签:style   http   color   os   art   io   

原文地址:http://blog.csdn.net/accelerator_/article/details/37927353

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!