UVA - 10601 Cubes (组合+置换)

来源:互联网 发布:macbookpro必装软件 编辑:程序博客网 时间:2024/04/30 08:29

Description

Download as PDF

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 one of them could be rotated and put next to the other, so that the corresponding edges of the two cubes are equally colored.

 

Input

The first line of input contains T (1≤T≤60), the number of test cases. Then T test cases follow. Each test case consists of one line containing 12 integers. Each of them denotes the color of the corresponding rod. The colors are numbers between 1 and 6.

 

Output

The output for one test consists of one integer on a line - the number of ways one can construct a cube with the described properties.

 

Sample Input

Sample Output

3

1 2 2 2 2 2 2 2 2 2 2 2

1 1 2 2 2 2 2 2 2 2 2 2

1 1 2 2 3 3 4 4 5 5 6 6

1

5

312120

 

Problem source: Bulgarian National Olympiad in Informatics 2003

Problem submitter: Ivaylo Riskov

Problem solution: Ivaylo Riskov, K M Hasan

题意:有12条边,每个边有指定的颜色,组成一个立方体,求种数

思路:参看cxlove GG的博客

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>typedef long long ll;using namespace std;const int maxn = 20;int a[maxn], b[maxn];ll c[maxn][maxn];void init() {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] + c[i-1][j-1];}}ll solve(int k) {ll sum = 1;int n = 0;for (int i = 0; i < 6; i++)if (b[i] % k == 0) {b[i] /= k;n += b[i]; }else return 0;for (int i = 0; i < 6; i++) {sum *= c[n][b[i]];n -= b[i];}return sum;}ll still() {memcpy(b, a, sizeof(a));return solve(1);}ll point() {memcpy(b, a, sizeof(a));return 4*2*solve(3);}ll plane() {memcpy(b, a, sizeof(a));ll ans = 3*2*solve(4);memcpy(b, a, sizeof(a));return ans + 3*solve(2);}ll edge() {ll ans = 0;for (int i = 0; i < 6; i++)for (int j = 0; j < 6; j++) {memcpy(b, a, sizeof(b));b[i]--, b[j]--;if (b[i] < 0 || b[j] < 0)continue;ans += 6 * solve(2);}return ans;}ll polya() {ll ans = 0;ans += still();ans += point();ans += plane();ans += edge();return ans / 24;}int main() {init();int t, k;scanf("%d", &t);while (t--) {memset(a, 0, sizeof(a));for (int i = 0; i < 12; i++) {scanf("%d", &k);a[k-1]++;}printf("%lld\n", polya());}return 0;}


1 1
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 工商已吊销未注销要恢复营业怎么办 中专类学校取消后在编的老师怎么办 情迁微信内置抢红包版本过低怎么办 船运货给客户货到他不要怎么办 摩拜单车锁了还在计费怎么办 旧公司股份现成立新公司股份怎么办 比亚迪l3线路进水打不着火怎么办 新成立的建筑公司没有业绩怎么办 被骗做了深圳国税实名办税怎么办 天猫精灵生活灯老是离线怎么办 电信合约没到期不想用了怎么办 电信合约卡到期不想用了怎么办 欧普照明平板灯坏了怎么办 交通违章处理了但系统没更新怎么办 车里的空调一直吹的是热气怎么办 丰田雷凌保养手册丢了怎么办 海尔电视两年主板坏了怎么办 海信电视保修期内主板坏了怎么办 乐视电视的主板坏了怎么办 车电瓶没电了打不着火怎么办 面包车没电了打不着火怎么办 汽车电瓶没电了打不着火怎么办 自动挡的车没有电打不起来火怎么办 自动挡汽车没电了打不着火怎么办 自动挡小车没电了打不着火怎么办 被4s店销售骗了怎么办 宇通客车尿素泵不工作怎么办 汽车打蜡不小心打在车帮怎么办 海信电视怎么安装第三方软件怎么办 网上买票的时候不想用学生票怎么办 南方公园完整破碎讲话嘴不动怎么办 同一个安全员被锁在两个项目怎么办 家长拖欠家教老师的课时费怎么办 合同没到期房东不退押金怎么办 租房合同没到期房东要违约怎么办 档案存放费交了一年的延期怎么办 天津房子卖了户口没地方迁怎么办 中国到美国读计算机硕士签证怎么办 在江苏大学去德国读研怎么办? 宿舍上下铺的床一动就响怎么办 自助取款机存款忘打印了凭条怎么办