【题意】

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

  否则输出-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. lucene正向索引——正向信息,Index –> Segments (segments.gen, segments_N) –> Field(fnm, fdx, fdt) –> Term (tvx, tvd, tvf)

    转自:http://www.cnblogs.com/forfuture1978/archive/2009/12/14/1623599.html 上面曾经交代过,Lucene保存了从Index到Segm ...

  2. 【解决方案】IP代理池设计与解决方案

    一.背景 爬虫服务请求量大,为了应对反爬措施,增加爬虫的爬取效率和代理IP使用率,需要设计一个IP代理池,满足以下需求: 定时任务获取第三方代理 及时剔除IP代理池中失效的IP 业务隔离IP 若IP未 ...

  3. Co-Clustering_Reproducing

    调包一时爽,复现马上躺. Co-Clustering 注意右上角的:"Edit on GitHub",一开始疯狂吐槽没有源码,复现得非常难受,今天刚做完GM05中Algotirhm ...

  4. TynSerial基本数据类型序列(还原)

    TynSerial基本数据类型序列(还原) procedure TForm1.ToolButton17Click(Sender: TObject); var serial: TynSerial; be ...

  5. php7的扩展库安装方法

    转:https://www.cnblogs.com/to-be-rich/p/8001175.html 今天的知识点:1.php的再次编译不会对现有的php业务有影响,只有正式kill -USR2 p ...

  6. NLP 文本预处理

    1.不同类别文本量统计,类别不平衡差异 2.文本长度统计 3.文本处理,比如文本语料中简体与繁体共存,这会加大模型的学习难度.因此,他们对数据进行繁体转简体的处理. 同时,过滤掉了对分类没有任何作用的 ...

  7. 机器学习 - 算法 - SVM 支持向量机

    SVM 原理引入 支持向量机( SVM,Support Vector Machine ) 背景 2012年前较为火热, 但是在12年后被神经网络逼宫, 由于应用场景以及应用算法的不同, SVM还是需要 ...

  8. tensorflow cpu问题

    返回: -- ::] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 ...

  9. 013-多线程-基础-Fork/Join框架、parallelStream讲解

    一.概述 Fork/Join框架是Java7提供了的一个用于并行执行任务的框架, 是一个把大任务分割成若干个小任务,最终汇总每个小任务结果后得到大任务结果的框架. 它同ThreadPoolExecut ...

  10. kafka和zookeeper的配置文件优化配置

    zookeeper的配置 日志自动清理这两个参数都是在zoo.cfg中配置的:    autopurge.purgeInterval 这个参数指定了清理频率,单位是小时,需要填写一个1或更大的整数,默 ...