【题意】

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

  否则输出-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. 关于SQLServer 中行列互转的实例说明

    这几天在做一个招标系统中审批模块,其中关于报价信息这块,用到了pivot和unpivot来实现数据的行列互转,下面简单介绍一下,实际案例,便于回忆和记录相关的条件下使用的情况.pivot 与 unpi ...

  2. java读取excel文件数据导入mysql数据库

    这是我来公司的第二周的一个小学习任务,下面是实现过程: 1.建立maven工程(方便管理jar包) 在pom.xml导入 jxl,mysql-connector 依赖 可以在maven仓库搜索 2.建 ...

  3. 深入理解JVM虚拟机9:JVM监控工具与诊断实践

    转自https://juejin.im/post/59e6c1f26fb9a0451c397a8c jvm优化必知系列——监控工具 微信公众号[Java技术江湖]一位阿里 Java 工程师的技术小站. ...

  4. Git .gitignore中已添加文件路径,但仍未被忽略

    当文件之前已经被提交到仓库后,后面即使将文件路径添加到 .gitignore ,使用 git status 命令,依然会看到文件被修改. $ git status 位于分支 master 您的分支与上 ...

  5. Delphi BASE64单元EncdDecd的修改

    Delphi BASE64单元EncdDecd的修改 EncdDecd.pas两个函数声明: procedure EncodeStream(Input, Output: TStream);proced ...

  6. 如果前面的IO操作出问题了,按照我们代码的意思,不就try catch 了吗,这样的话线程就没关闭了,就会造成线程泄露。 那怎么解决这个问题呢,其实也简单,把关闭线程的方法写到finally里就可以了。

    https://mp.weixin.qq.com/s/WaNVT2bZFGHNO_mb5nK6vw 连HDFS源码大神都会犯的错之线程泄露(1) 西瓜老师 西瓜老师爱大数据 1月11日  

  7. Coherent Calculator

    计算逻辑 输入想要的参数后点击以下按钮进行计算和调整: Formula Bigger N Smaller N Bigger M Smaller M 所以在这个策略中Ft被Fixed在输入的值,其他的三 ...

  8. js求数组最大值方法

    定义数组 var arr = [-1, 1, 101, -52, 10, 1001, 1001] 1.es6拓展运算符... Math.max(...arr) 2.es5 apply(与方法1原理相同 ...

  9. 123457---com.twoapp.shuXueYouXi---小学数学口算

    com.twoapp.shuXueYouXi---小学数学口算

  10. iOS 越狱后OpenSSH安装报错

    转载自:https://www.jianshu.com/p/75f6d0f54d61 安装OpenSSH报错 尝试重启手机重新安装 将手机语言设置为英文状态 将手机设置为飞行模式,用wifi下载(我的 ...