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 ...
随机推荐
- 2018.10.16 NOIP模拟 膜法(组合数学)
传送门 原题,原题,全TM原题. 不得不说天天考原题. 其实这题我上个月做过类似的啊,加上dzyodzyodzyo之前有讲过考试直接切了. 要求的其实就是∑i=lr(ii−l+k)\sum _{i=l ...
- 2018.09.27 codeforces1045D. Interstellar battle(期望dp)
传送门 一道有意思的期望dp. 题意是给出一棵树,每个点最开始都有一个gg的概率,有m次修改,每次修改会把某个点gg的概率更换掉,让你求出每次修改之后整个树被分成的连通块的数量的期望(gg掉的点不算) ...
- HDU 2037 今年暑假不AC (区间贪心)
题意:又是中文题... 析:先说一下区间贪心的一个定理,选择不相交的区间:数轴上有n个开区间(ai, bi).选择尽量多的区间,使得这些区间两两不相交,贪心策略是,一定是选bi小的.(想一下为什么). ...
- Redis配置总结
一:常用配置 1.bind,格式为bind 127.0.0.1:这个是很重要的配置,如果bind 127.0.0.1则外部网络是访问不了的(如果外部网络要访问还要开放端口) 2.port,格式为por ...
- python调用dll方法
在python中调用dll文件中的接口比较简单,实例代码如下: 如我们有一个test.dll文件,内部定义如下: extern "C"{ int __stdcall test( v ...
- 4) Maven 安装
# ----------------------------------------------------------------------------# Maven2 Start Up Batc ...
- Difference between the Bill of distribution and sourcing rule.
https://forums.oracle.com/thread/936768 This is from a users guide Oracle Supply Chain Planning ...
- Python学习-16.Python中的错误处理
虽然叫错误,但跟 C# 中的异常是一回事.只不过 Python 中叫错误(Error)而 C# 中叫异常(Exception). 先手工产生一个异常: file = open('','r') 上面一句 ...
- 开源WebGIS实施方案(六):空间数据(PostGIS)与GeoServer服务迁移
研发环境的变更,或者研发完成进行项目现场实施.运维的时候,经常就会面临数据及服务的迁移,这其中就包含空间数据以及GeoServer服务的迁移工作. 这里需要提醒的是:如果采用的是类似的开源WebGIS ...
- Kafka consumer的参数
earliest: 当各分区下有已提交的offset时,从提交的offset开始消费:无提交的offset时,从头开始消费 latest :当各分区下有已提交的offset时,从提交的offset开始 ...