codeforces510C. Fox And Names【拓扑排序】
来源:互联网 发布:阅读软件塞班版 编辑:程序博客网 时间:2024/06/05 10:21
题意:给出N个字符串判断这些字符串是否是按照某一个26个字母的排列的字典序排列的如果有输出这个序列
拓扑排序
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;const int maxn=110;char str[maxn][maxn];int indgree[30];bool map[30][30];bool vis[maxn][maxn];int ans[30];bool topo(){for(int i=0;i<26;++i){int pos=-1;for(int j=0;j<26;++j){if(indgree[j]==0){pos=j;break;}}if(pos==-1)return false;ans[i]=pos;indgree[pos]=-1;for(int j=0;j<26;++j){if(map[pos][j]){indgree[j]--;}}}return true;}int main(){int n,i,j,k;scanf("%d",&n);for(i=1;i<=n;++i){scanf("%s",str[i]+1);}bool sign=true;for(i=1;i<=100;++i){if(!sign)break;for(j=1;j<=n;++j){if(str[j][i]!=str[j-1][i]&&!vis[j][j-1]){if(i<=strlen(str[j-1]+1)&&i>strlen(str[j]+1)){sign=false;break;}if(i>strlen(str[j-1]+1)){vis[j][j-1]=true;continue;}if(!map[str[j-1][i]-'a'][str[j][i]-'a'])indgree[str[j][i]-'a']++;map[str[j-1][i]-'a'][str[j][i]-'a']=true;vis[j][j-1]=true;}}}if(!topo()||!sign){printf("Impossible\n");}else {for(i=0;i<26;++i){printf("%c",ans[i]+'a');}}printf("\n");return 0;}
0 0
- codeforces510C. Fox And Names【拓扑排序】
- 拓扑排序 Codecorces510C Fox And Names
- 拓扑排序 Fox And Names : CodeForces
- codeforces 510C Fox And Names 拓扑排序
- Codeforces 510C - Fox And Names (拓扑排序)
- CF 510C(Fox And Names-拓扑排序)
- CodeForces510 C. Fox And Names(拓扑排序)
- 510C Fox And Names(拓扑排序)
- Codeforces 510C Fox And Names 拓扑排序
- CF 510C Fox And Names(拓扑排序)
- codeforces 510c Fox And Names 拓扑排序
- [CodeForces 510C]Fox And Names[字典序][拓扑排序]
- Codeforces 510C Fox And Names 拓扑排序
- [CodeForces] 510 C Fox And Names [拓扑排序]
- 拓扑排序 CodeForces - 510C Fox And Names
- CF 510C Fox And Names【拓扑排序】
- Codeforces 510C Fox And Names【拓扑排序】
- CF512A:Fox And Names(拓扑排序 & 字典树)
- codeforces611B. New Year and Old Property
- Zabbix 使用 JMX 方式监控 Tomcat
- Java NIO:NIO概述
- poj 1721 CARDS(置换)
- CSS盒子模型
- codeforces510C. Fox And Names【拓扑排序】
- codeforces510B. Fox And Two Dots【dfs】
- 网站分析与优化
- 使用notepad++删除^M字符
- 关于有偿提供拼图响应式后台的通知
- codeforces55B. Smallest number
- SAP 销售与分销模块定价完全实施手册(SAP SD Pricing Handbook)
- 【BZOJ2438】杀人游戏,tarjan缩点+简单的概率计算
- codeforces580C. Kefa and Park【dfs】