zoukankan      html  css  js  c++  java
  • [蓝桥杯2015初赛]手链样式

    题目链接:http://oj.ecustacm.cn/problem.php?id=1254

    题目描述

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

    输出

    请你输出该整数。不要输出任何多余的内容或说明性的文字。

    思想:

    暴力枚举,我们直接把每一次得到的串先复制拼接一下(模拟旋转)成环,再翻转一下,如果两次得到的串在已得的串里面没有就加入

    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <map>
    #include <stack>
    #include <set>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <iomanip>
    #include <time.h>
    
    #define LL long long
    #define INF 0x3f3f3f3f
    #define ls nod<<1
    #define rs (nod<<1)+1
    
    const int maxn = 1e5 + 10 ;
    const LL mod = 20010905;
    
    std::vector<std::string> v;
    
    int main() {
        std::string str = "aaabbbbccccc";
        int sum = 0;
        do {
            std::vector<std::string>::iterator it;
            for (it = v.begin();it != v.end();it++) {
                if((*it).find(str, 0) != std::string::npos)
                {
                    break;
                }
            }
            if (it != v.end())
                continue;
            std::string str2 = str + str;  //可以任意转动的缘故
            v.push_back(str2);
            reverse(str2.begin(), str2.end());  //可以任意翻转的缘故
            v.push_back(str2);
            sum++;
        }while(next_permutation(str.begin(), str.end()));
        printf("%d
    ",sum);
    }
  • 相关阅读:
    cent os 6.8 php 5.6 安装ffmpeg扩展
    Linux查找目录下文件包含关键字
    python生成随机验证码
    zabbix添加任务计划和sshd文件修改key
    OS模块
    python模块
    python内建函数
    python3 爬煎蛋ooxx妹子图
    ssm整合-Sping整合Mybatis框架配置事务07
    ssm整合-Sping整合Mybatis框架06
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/12241397.html
Copyright © 2011-2022 走看看