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 ...
随机推荐
- Largest product from 3 integers
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- 2018.10.14 loj#6011. 「网络流 24 题」运输问题(费用流)
传送门 费用流入门题. 直接按照题意模拟. 把货物的数量当做容量建边. 然后跑一次最小费用流和最大费用流就行了. 代码: #include<bits/stdc++.h> #define N ...
- ansible-playbook 主机变量1
hosts 配置后可以支持指定 端口,密码等其他变量 [root@10_1_162_39 host_vars]# ll total -rw-r--r-- root root May : hosts - ...
- 20155218 2016-2017-2 《Java程序设计》第6周学习总结
20155218 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 Java将输入/输出抽象化为串流,数据有来源及目的地,衔接两者的是串流对象. dump()方 ...
- struts2 一些注解
实现的JSP页面位置 web-root/jsp/user/add.jsp /update.jsp // /* @Namespace("/t") @AllowedMethods(va ...
- (树的直径)LightOJ -- 1094
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#problem/C 求树的直径,这里只不过给每条边增加一个边长属性,变成 ...
- hdu 2048 神上帝以及老天爷
题目 解题思路: 典型的错排题目 首先求出所有的拿错的情况,然后求出错排的所有情况,以前者除以后者就是百分比 现在求对应的所有都拿错的情况.容易知道,f(1)=0,f(2 ...
- Java对象的serialVersion序列化和反序列化
Java基础学习总结——Java对象的序列化和反序列化 一.序列化和反序列化的概念 把对象转换为字节序列的过程称为对象的序列化. 把字节序列恢复为对象的过程称为对象的反序列化. 对象的序列化主要有两种 ...
- linux 下mysql/php编译配置参数
mysql cmake 编译参数 cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \-DSYSCONFDIR=/opt/mysql/etc \-DMYSQL_DATAD ...
- MaxScript调用DotNet时命名空间的问题
Fn GetSpecialFolder argEnumName = (DotNetClass "System.Environment").GetFolderPath (Execut ...