【题意】

  这个题目就是问,是否存在每个人对应每一种颜色,如果存在则输出字典序最小的。

  否则输出-1

【题解】

  利用next_permutation来构造36种情况。记住最后还需要排序一遍。

  然后用子序列判断是否存在。while写即可。

 #include<bits/stdc++.h>
using namespace std;
string Ans[] ;
string T[] ;
string Name[] = {"Alice","Bob","Yazid"};
string name[] = {"alice" ,"bob","yazid"};
string Color[] = {"red","blue","green"};
string str; int cnt = ; void Init(){
int N_idx[] = {,,};
int C_idx[] = {,,}; do{
do{
for(int i=;i<;i++)
T[cnt] += name[N_idx[i]] + "is" + Color[C_idx[i]] ;
for(int i=;i<;i++)
Ans[cnt] += Name[N_idx[i]] + " is " + Color[C_idx[i]] + ".";
cnt ++ ;
}while(next_permutation(C_idx,C_idx+));
}while( next_permutation(N_idx,N_idx+));
}
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(NULL) , cout.tie(NULL) ;
Init(); sort( T , T + );
sort( Ans , Ans + ); //cout << T[0].length() << endl; /*
for( auto x : Ans ){
cout << x << endl;
}
*/ int kase ;
cin >> kase ;
while( kase -- ){
cin >> str;
int len = str.length() ;
int i , j , k ;
for(k = ; k < ; k++ ){
i = j = ;
while( i < && j < len ){
if( T[k][i] == str[j] ) i++ ;
j ++ ;
}
if( i == ){
break;
}
}
if( k == ){
cout << "No solution." << endl;
}else{
cout << Ans[k] << endl;
}
}
return ;
}
/*
4
aliceisredbobisblueyazidisgreen
aliceisgreenbobisgreenyazidisgreen
aliceisyellowbobisblueyazidisgreen
xxyazidxxisxxgreenxxbobisblueaxlxixcxexixsxrxexdx
*/

【全排列+子序列】Color的更多相关文章

  1. [BZOJ4416][SHOI2013]阶乘字符串(子集DP)

    怎么也没想到是子集DP,想到了应该就没什么难度了. 首先n>21时必定为NO. g[i][j]表示位置i后的第一个字母j在哪个位置,n*21求出. f[S]表示S的所有全排列子序列出现的最后末尾 ...

  2. PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)

    1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. S ...

  3. [BJWC2018]最长上升子序列

    十分感谢GXZ大佬的讲解,此处致以敬意!emmmm在初学状压DP时就理解了如此精妙的一道题,感到很开森~ \(Address\) ________________ #\(\color{red}{\ma ...

  4. [LeetCode] “全排列”问题系列(二) - 基于全排列本身的问题,例题: Next Permutation , Permutation Sequence

    一.开篇 既上一篇<交换法生成全排列及其应用> 后,这里讲的是基于全排列 (Permutation)本身的一些问题,包括:求下一个全排列(Next Permutation):求指定位置的全 ...

  5. LeetCode:60. Permutation Sequence,n全排列的第k个子列

    LeetCode:60. Permutation Sequence,n全排列的第k个子列 : 题目: LeetCode:60. Permutation Sequence 描述: The set [1, ...

  6. Color the Ball(懵逼题)

    Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. 1045. Favorite Color Stripe (30) -LCS允许元素重复

    题目如下: Eva is trying to make her own color stripe out of a given one. She would like to keep only her ...

  8. PAT 甲级 1045 Favorite Color Stripe

    https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...

  9. 1045 Favorite Color Stripe 动态规划

    1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...

随机推荐

  1. 入门cmake,窥探编译过程

    https://www.cnblogs.com/hg-love-dfc/p/10242391.html https://www.cnblogs.com/hg-love-dfc/p/10244328.h ...

  2. ICEM-一种三维Y型网格

    ​原视频下载地址:https://yunpan.cn/cLHD9ewat8v9a  访问密码 0f0f

  3. vue学习一

    自己根据网上的教程新建了一个vue_tes项目.想自己在里面修改,添加各种内容.新建了几个vue页面,一直想把他们关联起来展示.非常心急,没有仔细去看文档,而且网上的教程都是单页面的.很好理解.自己创 ...

  4. Leetcode题 257. Binary Tree Paths

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  5. Buuctf pwn1 详细wp

    目录 程序基本信息 程序溢出点 确定返回地址 编写exp脚本 成功getshell 程序基本信息 我们可以看到这是一个64程序,没有保护开启. 程序溢出点 gets函数可以读取无限字符,存在栈溢出. ...

  6. C++ STL介绍——String类

    目录 1.简介 2.string类成员函数汇总 3.String类的构造函数以及析构函数 4.获取字符串长度 5.获取字符串元素 6.字符串比较方法 7.字符串输入输出 8.字符串查找函数 1.简介 ...

  7. javascript 的垃圾回收机制讲一下

    定义:指一块被分配的内存既不能使用,又不能回收,直到浏览器进程结束. 像 C 这样的编程语言,具有低级内存管理原语,如 malloc()和 free().开发人员使用这些原语显式地对操作系统的内存进行 ...

  8. android studio: 实现类似于XCode中的#pragma mark的效果

    代码行数写多了,想找一个指定的方法真困难,关键有时候记不住方法的名字,用Ctrl+O也不好使,突然想到以前做iOS开发时,XCode里有一个#pragma mark的功能,很好用:在代码中定义这样一个 ...

  9. apk增加系统签名的方法

    1.命令行方法给apk加系统签名在Linux环境:java -Djava.library.path=. -jar signapk.jar platform.x509.pem platform.pk8 ...

  10. [webpack]手写一个mvp版本的webpack

    let fs = require('fs'); let path = require('path'); let babylon = require('babylon'); // Babylon 把源码 ...