省委代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define maxn 100
#define maxm 10000using namespace std;struct edge{int next,to;
}e[maxm];int point[maxn],cnt;
int l,r,q[maxn],in[maxn];
char s[110][110];void addedge(int x,int y)
{e[++cnt].next=point[x];e[cnt].to=y;point[x]=cnt;
}void toposort()
{l=r=0;for(int i=0;i<26;i++)if(in[i]==0)q[++r]=i;while(l<r){int x=q[++l];for(int i=point[x];i;i=e[i].next){int y=e[i].to;in[y]--;if(in[y]==0)q[++r]=y;}}
}int main()
{scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%s",s[i]);for(int i=1;i<n;i++){int len1=strlen(s[i]);int len2=strlen(s[i+1]);bool flag=0;for(int j=0;j<min(len1,len2);j++)if(s[i][j]==s[i+1][j])continue;else{flag=1;in[s[i+1][j]-'a']++;addedge(s[i][j]-'a',s[i+1][j]-'a');break;}if(flag==0 && len2<len1){printf("Impossible");return 0;}}toposort();if(l<26)printf("Impossible");elsefor(int i=1;i<=26;i++)printf("%c",q[i]+'a');return 0;
}

转载于:https://www.cnblogs.com/ShineEternal/p/11221382.html

CF510C Fox And Names——拓扑排序练习相关推荐

  1. 输出dag的所有拓扑排序序列_算法学习笔记(53): 拓扑排序

    拓扑排序是对DAG(有向无环图)上的节点进行排序,使得对于每一条有向边 , 都在 之前出现.简单地说,是在不破坏节点 先后顺序的前提下,把DAG拉成一条链.如果以游戏中的科技树(虽然名字带树,其实常常 ...

  2. *【CF#510C】Fox And Names (拓扑排序)

    题干: Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: " ...

  3. 拓扑排序 Codeforces Round #290 (Div. 2) C. Fox And Names

    题目传送门 1 /* 2 给出n个字符串,求是否有一个"字典序"使得n个字符串是从小到大排序 3 拓扑排序 4 详细解释:http://www.2cto.com/kf/201502 ...

  4. HDU 3342 Legal or Not(拓扑排序)

    描述 ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that ju ...

  5. 【HDU - 3342】Legal or Not(拓扑排序)

    题干: ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that j ...

  6. Dwarves(拓扑排序+字符串使用map量化表示)

    题目描述 Once upon a time, there arose a huge discussion among the dwarves in Dwarfland. The government w ...

  7. 【图论】有向无环图的拓扑排序

    1. 引言 有向无环图(Directed Acyclic Graph, DAG)是有向图的一种,字面意思的理解就是图中没有环.常常被用来表示事件之间的驱动依赖关系,管理任务之间的调度.拓扑排序是对DA ...

  8. C#实现有向无环图(DAG)拓扑排序

    对一个有向无环图(Directed Acyclic Graph简称DAG)G进行拓扑排序,是将G中所有顶点排成一个线性序列,使得图中任意一对顶点u和v,若边(u,v)∈E(G),则u在线性序列中出现在 ...

  9. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

最新文章

  1. oracle sql now函数,postgresql的now()与Oracle的sysdate区别说明
  2. Vue+blockly 制作与自定义美化
  3. C++11的for循环使用auto的新用法
  4. uva 11012——Cosmic Cabbages
  5. C++知识点:typedef struct、printf
  6. 关于IAP:测试时能获取产品价格,却不能获取产品名称的问题
  7. lvs之 lvs+nginx+tomcat_1、tomcat_2+redis(lvs dr 模式)
  8. async 与 await
  9. 数据库实验8 数据库安全性(用户与权限管理)实验
  10. 几校联考——day1题解
  11. 反射(一)动态加载类
  12. VSCODE: 快速生成html框架
  13. 计算机操作系统张尧学第四章课后答案,清华大学出版社-图书详情-《计算机操作系统教程(第4版)习题解答与实验指导》...
  14. HTML 字体颜色 色号对照表
  15. 【码农话健身】入门级颈部锻炼
  16. 解决Page index must not be less than zero问题
  17. 华为ensp_三层交换
  18. 微信小程序之身份证照片正反上传
  19. 批量修改文件内容(Python版)
  20. 电话面试经历 - 负暄琐话 - CSDNBlog

热门文章

  1. 充分发挥bpl包的作用
  2. leetCode刷题-第二题两数之和
  3. 编译原理实验一预习报告
  4. 四个标志位SF,ZF,OF,CF
  5. visual studio code安装shadertoy特效环境
  6. Jackson 注解 -- 使用 Map存储JSON
  7. 操作系统(十四)进程调度的时机、调度方式
  8. 计算机组装与维护补考论文,计算机组装与维护期末论文
  9. GDB 调试多进程或者多线程应用
  10. linux dns语法检测工具,DNS解析检查工具之nslookup