ConstStar
发布于 2023-01-26 / 106 阅读 / 0 评论 / 0 点赞

蓝桥杯2015年A组:手链样式

问题描述

小明有3颗红珊瑚,4颗白珊瑚,5颗黄玛瑙。
他想用它们串成一圈作为手链,送给女朋友。
现在小明想知道:如果考虑手链可以随意转动或翻转,一共可以有多少不同的组合样式呢?

解决方案

思路

全排列

代码

#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main() {

    string buf = "111222233333";
    set<string> s;

    set<string> s_double;		//// 存储 转动或翻转 的样式


    do {

        int is_find = false;
        for (auto item: s_double) {
            if (item.find(buf) != string::npos) {
                is_find = true;
                break;
            }
        }


        string buf_double = buf + buf;
        s_double.insert(buf_double);
        s_double.insert(string(buf_double.rbegin(), buf_double.rend()));

        if (is_find)
            continue;

        s.insert(buf);

    } while (next_permutation(buf.begin(), buf.end()));

    cout << s.size();

    return 0;
}

输出

1170

评论