#include<iostream>
#include<algorithm>
#define MAXN 26
#define MAX 300
using namespace std; bool floy[MAXN][MAXN];
char var[MAX];
char cons[MAX];
int a[MAXN];
void tran_var();
void give_floy();
bool is_ok();
void floyd();
int main()
{
//freopen("acm.acm","r",stdin);
int len;
while(gets(var))
{
memset(floy,false,sizeof(floy));
memset(a,,sizeof(a));
gets(cons);
tran_var();
// cout<<var<<endl;
give_floy();
floyd();
len = strlen(var);
// cout<<len;
sort(var,var + len);
do
{
//cout<<"0000000000"<<endl;
if(is_ok())
cout<<var<<endl;
}while(next_permutation(var,var+len));
cout<<endl;
}
} void tran_var()
{
int i;
int j;
int len = strlen(var);
for(i = ,j = ; i < len; i += )
{
var[j] = var[i];
++ j;
}
var[j] = '\0';
} void give_floy()
{
int i;
int j;
int len = strlen(cons);
for(i = ; i < len; i += )
{
floy[cons[i] - 'a'][cons[i+] - 'a'] = true;
}
// floyd();
} void floyd()
{
int i;
int j;
int k;
for(k = ; k < MAXN; ++ k)
{
for(i = ; i < MAXN; ++ i)
{
for(j = ; j < MAXN; ++ j)
{
if(floy[i][k] && floy[k][j])
{
floy[i][j] = true;
}
}
}
}
} bool is_ok()
{
int i;
int j;
int len = strlen(var);
// cout<<len<<endl;
for(i = ; i < len; ++ i)
{
a[var[i] - 'a'] = i;
}
// for(i = 0; i < len; ++ i)
// {
// cout<<a[i]<<" ";
// }
// cout<<endl;
for(i = ; i < MAXN; ++ i)
{
for(j = ; j < MAXN; ++ j)
{
if(floy[i][j] && a[i] > a[j])
return false;
}
}
return true;
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1270的更多相关文章

  1. POJ 1270 Following Orders

    Following Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4902   Accepted: 1982 ...

  2. poj 1270(toposort)

    http://poj.org/problem?id=1270 题意:给一个字符串,然后再给你一些规则,要你把所有的情况都按照字典序进行输出. 思路:很明显这肯定要用到拓扑排序,当然看到discuss里 ...

  3. poj 1270(dfs+拓扑排序)

    题目链接:http://poj.org/problem?id=1270 思路:就是一简单的dfs+拓扑排序,然后就是按字典序输出所有的情况. http://paste.ubuntu.com/59872 ...

  4. POJ 1270 Following Orders 拓扑排序

    http://poj.org/problem?id=1270 题目大意: 给你一串序列,然后再给你他们部分的大小,要求你输出他们从小到大的所有排列. 如a b f g 然后 a<b ,b< ...

  5. POJ 1270 Following Orders (拓扑排序,dfs枚举)

    题意:每组数据给出两行,第一行给出变量,第二行给出约束关系,每个约束包含两个变量x,y,表示x<y.    要求:当x<y时,x排在y前面.让你输出所有满足该约束的有序集. 思路:用拓扑排 ...

  6. POJ 1270 Following Orders(拓扑排序)题解

    Description Order is an important concept in mathematics and in computer science. For example, Zorn' ...

  7. POJ 1270 Following Orders(拓扑排序)

    题意: 给两行字符串,第一行为一组变量,第二行时一组约束(每个约束包含两个变量,x y 表示 x <y).输出满足约束的所有字符串序列. 思路:拓扑排序 + 深度优先搜索(DFS算法) 课本代码 ...

  8. poj 1270 Following Orders (拓扑排序+回溯)

    Following Orders Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5473   Accepted: 2239 ...

  9. Day4 - H - Following Orders POJ - 1270

    Order is an important concept in mathematics and in computer science. For example, Zorn's Lemma stat ...

随机推荐

  1. 做SEO都需要具备哪些方面的知识

    做seo需要了解的基本知识有利于seo工作的进行 一.了解搜索引擎的工作原理 搜索引擎的基本工作原理包括如下三个过程: 1.首先在互联网中发现.搜集网页信息; 2.同时对信息进行提取和组织建立索引库; ...

  2. bootstrap中让图片自适应不同的分辨率的方法

    boostrap中加上这个样式class="img-responsive"图片就可以自适应,手机端同样适用 详细介绍请查看全文:https://cnblogs.com/qianzf ...

  3. Django入门与实践-第11章:URL 分发(完结)

    http://127.0.0.1:8000http://127.0.0.1:8000/boards/1/http://127.0.0.1:8000/boards/2/http://127.0.0.1: ...

  4. linux配置ip 网关 和dns(转)

    原文地址:http://blog.csdn.net/ztz0223/article/details/5800665 Linux下面配置ip很容易的,并没有网上说的那么复杂,我的linux系统是rhel ...

  5. 用node.js写个在Bash上对字符串进行Base64或URL的encode和decode脚本

    一:自己这段时间经常要用到Base64编码和URL编码,写个编译型语言有点麻烦干脆就用node.js弄了个,弄好后在/etc/profile里加上alias就能完成工具的配置,先上代码: functi ...

  6. 配置 struts2 时掉进 web.xml 的坑

    这个声明不好用 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quo ...

  7. redis只加载AOF文件

    如果同时配置写AOF和RDB两种文件,但在redis启动时,只会加载AOF,除非配置只写RDB,才会加载RDB文件,也因此AOF文件必须是全量数据,所以会越来越大,这缺点也将是redis优化的一个方向 ...

  8. C语言printf的格式

    例1 int a = 12345;printf("%6d",a); // 输出6位不够左边补空格printf("%.6d",a); // 输出6位不够左边补0例 ...

  9. Linux下的ICMP反弹后门:PRISM

    搜索的时候无意中看见的这款基于ping的ICMP后门.于是到作者的github上看看,居然是阴文的,为了过级,只能强忍着看了,学生狗伤不起.还好比较简单易懂,正如简介说的一样:“PRISM is an ...

  10. 开源一款强大的文件服务组件(QJ_FileCenter)(系列一)

    系列文章 1. 开源一款强大的文件服务组件(QJ_FileCenter)(系列一) 2. 开源一款强大的文件服务组件(QJ_FileCenter)(系列二 安装说明) 3. 开源一款强大的文件服务组件 ...