POJ 1270
#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的更多相关文章
- POJ 1270 Following Orders
Following Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4902 Accepted: 1982 ...
- poj 1270(toposort)
http://poj.org/problem?id=1270 题意:给一个字符串,然后再给你一些规则,要你把所有的情况都按照字典序进行输出. 思路:很明显这肯定要用到拓扑排序,当然看到discuss里 ...
- poj 1270(dfs+拓扑排序)
题目链接:http://poj.org/problem?id=1270 思路:就是一简单的dfs+拓扑排序,然后就是按字典序输出所有的情况. http://paste.ubuntu.com/59872 ...
- POJ 1270 Following Orders 拓扑排序
http://poj.org/problem?id=1270 题目大意: 给你一串序列,然后再给你他们部分的大小,要求你输出他们从小到大的所有排列. 如a b f g 然后 a<b ,b< ...
- POJ 1270 Following Orders (拓扑排序,dfs枚举)
题意:每组数据给出两行,第一行给出变量,第二行给出约束关系,每个约束包含两个变量x,y,表示x<y. 要求:当x<y时,x排在y前面.让你输出所有满足该约束的有序集. 思路:用拓扑排 ...
- POJ 1270 Following Orders(拓扑排序)题解
Description Order is an important concept in mathematics and in computer science. For example, Zorn' ...
- POJ 1270 Following Orders(拓扑排序)
题意: 给两行字符串,第一行为一组变量,第二行时一组约束(每个约束包含两个变量,x y 表示 x <y).输出满足约束的所有字符串序列. 思路:拓扑排序 + 深度优先搜索(DFS算法) 课本代码 ...
- poj 1270 Following Orders (拓扑排序+回溯)
Following Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5473 Accepted: 2239 ...
- Day4 - H - Following Orders POJ - 1270
Order is an important concept in mathematics and in computer science. For example, Zorn's Lemma stat ...
随机推荐
- Jigloo 下载 安装 GUI
这个需要授权,一直不能解决!! 网上找了很多,都觉不能访问,这个可以用Eclipse直接更新的 http://www.cloudgardensoftware.com/jigloo/update-sit ...
- 2018.09.25 bzoj3572: [Hnoi2014]世界树(虚树+树形dp)
传送门 虚树入门题? 好难啊. 在学习别人的写法之后终于过了. 这道题dp方程很好想. 主要是不好写. 简要说说思路吧. 显然最优值只能够从子树和父亲转移过来. 于是我们先dfs一遍用儿子更新父亲,然 ...
- Spring boot 出现的时间
Spring 4.0 ~ 4.3 不管商业操作如何,Spring还是继续发展, 2013年12月, Spring4.0 发布,这个版本开始支持JDK8 , 甚至比JDK8 的GA版本还要早3个月! 2 ...
- 微信JSSDK分享接口
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js& ...
- spring boot web项目在IDEA下热部署解决办法(四步搞定)
最近在用spring boot 做一个web站点,修改了类.html.js等,刷新页面,没有生效,非要手动去make一下或者重启,大大降低了开发效率. 什么是热部署? 应用启动后会把编译好的Class ...
- derective示例
1.指令的定义 .directive('haproxySetting', [ function () { return { restrict: 'AEC', scope: { haproxy: '=' ...
- js限制上传图片类型和大小
<script type="text/javascript"> function checkFile(brandLogo){ var file=brandLogo.va ...
- MySQL外键使用及说明详解
一.外键约束 MySQL通过外键约束来保证表与表之间的数据的完整性和准确性. 外键的使用条件: 1.两个表必须是InnoDB表,MyISAM表暂时不支持外键(据说以后的版本有可能支持,但至少目前不支持 ...
- MOD13A1: MODIS/Terra Vegetation Indices 16-Day L3 Global 500 m SIN Grid V006
https://lpdaac.usgs.gov/node/838 Description The MOD13A1 Version 6 product provides a Vegetation Ind ...
- (线段树 区间合并更新)Tunnel Warfare --hdu --1540
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1540 http://acm.hust.edu.cn/vjudge/contest/view.action ...