10601 - Cubes(Ploya)

UVA 10601 - Cubes

题目链接

题意:给定正方体12条棱的颜色,要求用这些棱能组成多少不同的正方体

思路:利用ploya定理去求解,分类讨论,正方体一共24种旋转。相应的旋转方式有4种:

1、不动

2、沿两面中点连线旋转

3、沿对顶点连线旋转

4、沿两棱中点连线旋转

简单推算出每种情况相应的循环组数。在加上组合数学去进行选择颜色求解。注意第4种情况中,有两条棱和其它的循环长度是不同的,能够枚举然后扣掉讨论。

代码:

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

int t, color[6], save[6], c[13][13];

long long solve(int k) {
	long long sum = 0, ans = 1;
	for (int i = 0; i < 6; i++) {
		if (save[i] % k) return 0;
		save[i] /= k;
		sum += save[i];
	}
	for (int i = 0; i < 6; i++) {
		ans *= c[sum][save[i]];
		sum -= save[i];
 	}
 	return ans;
}

long long solve1() {
	memcpy(save, color, sizeof(save));
	return solve(1);
}

long long solve2() {
	memcpy(save, color, sizeof(save));
	long long ans = 6 * solve(4);
	memcpy(save, color, sizeof(save));
	return ans + 3 * solve(2);
}

long long solve3() {
	memcpy(save, color, sizeof(save));
	return 8 * solve(3);
}

long long solve4() {
	long long ans = 0;
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 6; j++) {
  			memcpy(save, color, sizeof(save));
  			save[i]--; save[j]--;
  			if (save[i] < 0 || save[j] < 0) continue;
  			ans += 6 * solve(2);
  		}
 	}
 	return ans;
}

int main() {
	for (int i = 0; i <= 12; i++) {
		c[i][0] = c[i][i] = 1;
		for (int j = 1; j < i; j++)
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
 	}
	scanf("%d", &t);
	while (t--) {
		int col;
		memset(color, 0, sizeof(color));
		for (int i = 0; i < 12; i++) {
			scanf("%d", &col);
			color[col - 1]++;
		}
		printf("%lld\n", (solve1() + solve2() + solve3() + solve4()) / 24);
	}
	return 0;
}
时间: 2024-11-06 17:45:41

10601 - Cubes(Ploya)的相关文章

UVA 10733 - The Colored Cubes(Ploya)

UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 UVA 10601 - Cubes这题类似 代码: #include <stdio.h> #include <string.h> unsigned long long n; int main() { while (~scanf("%llu", &n) &

uva 10601 - Cubes(置换)

题目链接:uva 10601 - Cubes 题目大意:有12根等长的小木棍,然后每根木棍,输入每根木棍颜色的编号,你的任务是统计出用它们拼出多少种不同的立方体,旋转之后完全相同的立方体被认定相同. 解题思路:polya,然后对应立方体有24种旋转: 不旋转(still):1种,循环长度为12 以对顶点为轴(rot_point):4组,循环长度为3 以对面中心为轴(rot_plane):3组,分别有90,180,270度旋转,分别对应循环长度3,2,3 以对边为轴(rot_edge):6组,除了

UVA - 10601 Cubes (组合+置换)

Description Problem B Cubes You are given 12 rods of equal length. Each of them is colored in certain color. Your task is to determine in how many different ways one can construct a cube using these rods as edges. Two cubes are considered equal if on

组合数学(P&#243;lya计数原理):UvaOJ 10601 Cubes

Cubes You are given 12 rods of equal length. Each of them is colored in certain color. Your task is to determine in how many different ways one can construct a cube using these rods as edges. Two cubes are considered equal if one of them could be rot

Uva 10601 Cubes 六维背包+burnside引理

题意:链接 方法:六维背包+burnside引理 解析: 挺好玩的一道burnside/polya题 结果我看到后既然这道题有颜色的限制,那么直接想起了card那道题.搞个背包什么的. 正方体有24种旋转方式. 面中心旋转 有 4 4 4 的置换 *3(90°) 有 2 2 2 2 2 2 的置换 *3(180°) 有 4 4 4 的置换 *3(90°) 棱中心旋转 有 1 1 2 2 2 2 的置换 *6 点对称旋转 有 3 3 3 3 的置换 *4 接下来呢? 怎么确定不变的置换的个数 对于

UVA - 10733 The Colored Cubes (置换)

All 6 sides of a cube are to becoated with paint. Each side is is coated uniformly with one color. When a selectionof n different colors of paint is available, how many different cubes can youmake? Note that any two cubes are onlyto be called "differ

【CF 520D】Cubes

[CF 520D]Cubes 怎么说呢--英语阅读题+超级大模拟-- 最重要的是知道怎么出来的数据...题意好懂 xy坐标内给出几个单位正方形 以正方形左下点坐标给出 y=0为地面 正方形下面或者左右下方至少存在一个正方形他才能稳定.. 正方形按0~m-1标号 每次只能取出不影响整体结构的正方形 甲乙玩一个游戏 交替取正方形 每取下一个按从左到右的顺序排好 得到一个大数 重点来了! 取出的数是m进制 转换为十进制是最终结果 甲希望结果最大 乙希望结果最小 问结果为多少 甲先取 题意明白了模拟就行

HDU1334_Perfect Cubes【水题】

Perfect Cubes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2192    Accepted Submission(s): 957 Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for n

Spoj-BOKAM143SOU Checking cubes.

Given a integer N. Find number of possible ways to represent N as a sum of at most five cubes. Input First line contains N. 1<=N<=125000. Output Output the result Example Input: 64 Output: 2 这种题目..直接暴力吧 1 #include<cstdio> 2 #include<iostrea