• 15年第六届蓝桥杯第七题_(string)



    手链样式

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

    请你提交该整数。不要填写任何多余的内容或说明性的文字。


     一开始以为是搜索,发现不行,想了一会儿没有思路,看了题解。。。用了一个比较慢,但是想法简单的方法。

    主要用了一些stl的函数,

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    #include<algorithm>
    #include<string>
    using namespace std;
    
    vector<string> strs;
    
    int main()
    {
        int sum=0;
        string str("aaabbbbccccc");
        do
        {
            vector<string>::iterator it;
            for(it=strs.begin();it!=strs.end();it++)
            {
                if((*it).find(str,0)!=string::npos)   //string的find函数
                    break;
            }
            if(it!=strs.end())
                continue;
            sum++;
            string newstr=str+str;  //转动
            strs.push_back(newstr);
            reverse(newstr.begin(),newstr.end());   //翻动
            strs.push_back(newstr);
        }while(next_permutation(str.begin(),str.end()));   //next_permutation函数
        cout<<sum<<endl;
        return 0;
    }
  • 相关阅读:
    GRIDVIEW导出到EXCEL
    .NET GRIDVIEW导出EXCEL
    C#自动列宽
    vue 路由跳转及传值和取值
    vue 部署windows nginx服务上
    vue多个代理配置vue.config
    mock常用规则
    git基础篇-常见错误
    git基础篇-使用教程
    win10 gitserver搭建
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/6486461.html
Copyright © 2020-2023  润新知