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.09.24 bzoj4977: [[Lydsy1708月赛]跳伞求生(贪心+线段树)
传送门 线段树好题. 这题一看我就想贪心. 先把a,b数组排序. 然后我们选择a数组中最大的b个数(不足b个就选a个数),分别贪心出在b数组中可以获得的最大贡献. 这时可以用线段树优化. 然后交上去只 ...
- c语言学生信息管理系统-学习结构体
#include<stdio.h> #include<stdlib.h> //结构体可以存放的学生信息最大个数,不可变变量 ; //学生信息结构体数组,最多可以存放100个学生 ...
- webuploader 文件上传插件 IE8/9 文件选择不上传
IE8/9下文件上传是采用flash模式,一直发送http://xxx.xxx.xx.xx:8888/crossdomain.xml请求,状态码为404,原因是上传文件的服务器未配置crossdoma ...
- Redis Cluster原理初步
目录 目录 1 1. 前言 1 2. 槽(slots) 1 3. 路由配置(node.conf) 1 4. 总slots数(cluster.h:16384) 2 5. key的路由 2 6. 将key ...
- MFC框架仿真<一>
#include "my.h" CMyWinApp theApp;/*起点->全局对象*/ void main() { CWinApp* pApp = AfxGetApp() ...
- 201709021工作日记--CAS解读
CAS主要参考博文:classtag http://www.jianshu.com/p/473e14d5ab2d CAS(Compare and swap)比较和替换是设计并发算法时用到的一种技术 ...
- ZOJ2481 Unique Ascending Array 2017-04-18 23:08 33人阅读 评论(0) 收藏
Unique Ascending Array Time Limit: 2 Seconds Memory Limit: 65536 KB Given an array of integers ...
- 获取Oracle EBS数据库跟踪文件方法
http://www.orapub.cn/posts/1624.html 一.以下在Oracle APP中执行: 1) Set the Profile Option: ‘Initialization ...
- Android SQLiteOpenHelper Sqlite数据库升级onUpgrade
Android Sqlite数据库升级,在Android APP开发之中,非常常见: 在确定原来的数据库版本号之后,在原来数据库版本号+1,就会执行onUpgrade方法,进行数据库升级操作: 在on ...
- JavaLogin小框架制作【精品博客】
做一个小登录接口方法,让用户传入用户名,密码,就可以知道登录的结果信息,并以接口监听的方式控制. 先看客户端执行效果: 输入正确: 输入错误: 模拟客户端使用登录小框架: package com.de ...