【题意】

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

  否则输出-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. Ideal打war包和tomcat展示War包

    今天主要是介绍如何把java代码把成war包以及如何在tomcat中放置展示.比较简单.大家可以看看 刚开始ideal 不知道打包,网上搜索了一个教程,看了半天没看会. 主要还是说的不太明白 . 不过 ...

  2. 详解JDBC对象

    1. DriverManager (1) 注册驱动 Class.forName("com.mysql.cj.jdbc.Driver"); 真正注册驱动的是驱动包下 jdbc 文件夹 ...

  3. 20165223《网络对抗技术》Exp7 网络欺诈防范

    目录 -- 网络欺诈防范 实践说明 实践目标 基础知识问答 实验工具学习 实践内容 简单应用SET工具建立冒名网站 ettercap DNS spoof 结合应用两种技术,用DNS spoof引导特定 ...

  4. Link static data in sql source control

    You can link data that doesn't change very often to SQL Source Control. This lets you commit data ch ...

  5. jquery获取html中当前元素对象,以及父对象,相邻的上一个对象,或下一个对象

    jsp代码: <span><input type="hidden" value="1" id="newInfo">& ...

  6. AT1357 n^p mod m(洛谷)

    题意翻译 求 n^p mod m 的值 输入格式 一行,为整数 n,m,p(注意顺序) 输出格式 一行,为 n^p mod m 的值 数据说明 对于100%的数据 1≤n,m≤10^91≤n,m≤10 ...

  7. android: 日期转Unix时间戳,Unix时间戳转日期,带时区

    1.UTC时间&GMT时间 UTC时间是时间标准时间(Universal Time Coordinated),UTC是根据原子钟来计算时间,误差非常小. UTC也是指零时区的时间,如果要表示其 ...

  8. VUE el-input正则验证

    ①只能输入大于0的整数 check(value) { let reg = /^[-]\d*$/; var _this = this; if (value) { if (new RegExp(reg). ...

  9. golang 循环创建闭包 问题排查

    ][]string{ { { "邀请码是什么", "我没有邀请码", "这个邀请码我可以随便填吗", "邀请码可以填他的手机号吗& ...

  10. myeclipse打开jsp后卡死的问题详解

    myeclipse打开jsp后卡死的问题详解   1,打开 Window -> Preferences -> General -> Editors -> File Associ ...