【全排列+子序列】Color
【题意】
这个题目就是问,是否存在每个人对应每一种颜色,如果存在则输出字典序最小的。
否则输出-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的更多相关文章
- [BZOJ4416][SHOI2013]阶乘字符串(子集DP)
怎么也没想到是子集DP,想到了应该就没什么难度了. 首先n>21时必定为NO. g[i][j]表示位置i后的第一个字母j在哪个位置,n*21求出. f[S]表示S的所有全排列子序列出现的最后末尾 ...
- 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 ...
- [BJWC2018]最长上升子序列
十分感谢GXZ大佬的讲解,此处致以敬意!emmmm在初学状压DP时就理解了如此精妙的一道题,感到很开森~ \(Address\) ________________ #\(\color{red}{\ma ...
- [LeetCode] “全排列”问题系列(二) - 基于全排列本身的问题,例题: Next Permutation , Permutation Sequence
一.开篇 既上一篇<交换法生成全排列及其应用> 后,这里讲的是基于全排列 (Permutation)本身的一些问题,包括:求下一个全排列(Next Permutation):求指定位置的全 ...
- LeetCode:60. Permutation Sequence,n全排列的第k个子列
LeetCode:60. Permutation Sequence,n全排列的第k个子列 : 题目: LeetCode:60. Permutation Sequence 描述: The set [1, ...
- Color the Ball(懵逼题)
Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- 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 ...
- PAT 甲级 1045 Favorite Color Stripe
https://pintia.cn/problem-sets/994805342720868352/problems/994805437411475456 Eva is trying to make ...
- 1045 Favorite Color Stripe 动态规划
1045 Favorite Color Stripe 1045. Favorite Color Stripe (30)Eva is trying to make her own color strip ...
随机推荐
- 走进JavaWeb技术世界11:单元测试框架Junit
JUnit你不知道的那些事儿 转自 老刘 码农翻身 2016-02-24 话说有一次Eric Gamma 坐飞机的时候偶遇Kent Beck(对,就是极限编程和TDD的发起人) , 两位大牛见面寒暄 ...
- scanf和fgets比较
scanf 长度限制 #include<stdio.h> int main() { char food[5]; printf("Enter food"); scanf( ...
- Delphi BASE64单元EncdDecd的修改
Delphi BASE64单元EncdDecd的修改 EncdDecd.pas两个函数声明: procedure EncodeStream(Input, Output: TStream);proced ...
- Vue——路由:登录状态的判断
在搭建的系统中,最基本的登录都是必须的,结合Vue的路由,涉及最多的就是登录状态的判断.也就是说,如果一个组件要校验登录状态,则在用户初始进入时,就要去判断用户是否登录,这里的校验登录状态就是本篇的重 ...
- VUE判断可用对象是否为空
方法一: JSON.stringify(formmanage_listVue.updataObj)=='{}' var data = {}; var b = (JSON.stringify(data) ...
- openwrt环境中某个运行在host端的软件如何安装到openwrt的$(STAGING_DIR_HOST)/bin下
可参考示例:见'git grep host-build.mk package/{system,utils}'
- E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem. 爆错解决办法
author :headsen chen date : 2019-06-06 10:09:06 root@ubuntu:~# apt-get remove java-1.8.0-openjdk E ...
- 阶段5 3.微服务项目【学成在线】_day09 课程预览 Eureka Feign_17-课程预览功能开发-前后端测试
启动前端代码 前端课程找到课程的发布页面 这样就打开了预览页面 结束
- Qt编写自定义控件46-树状导航栏
一.前言 树状导航栏控件是所有控件中最牛逼最经典最厉害的一个,在很多购买者中,使用频率也是最高,因为该导航控件集合了非常多的展示效果,比如左侧图标+右侧箭头+元素前面的图标设置+各种颜色设置等,全部涵 ...
- springboot下jar包方式运行Caused by: java.lang.ExceptionInInitializerError: null
idea调试过程中不会出现此问题,异常如下 org.springframework.beans.factory.BeanCreationException: Error creating bean w ...