510C

拓扑排序:将那些受影响的字母拓扑排序,其后的输出

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<queue>
  5. #include<algorithm>
  6. #include<cstring>
  7. using namespace std;
  8. queue<int>q;
  9. int n;
  10. vector<int>graph[];
  11. string s[];
  12. int mp[][];
  13. int in[];
  14. void toposort()
  15. {
  16. for(int i=;i<;i++)
  17. if(!in[i])
  18. {cout<<(char)(i+'a');q.push(i);}
  19. // if(!flag){cout<<"Impossible"<<endl;return;}
  20. while(!q.empty())
  21. {
  22. int u=q.front();q.pop();
  23. for(int i=;i<graph[u].size();i++)
  24. {
  25. int v=graph[u][i];
  26. in[v]--;
  27. if(in[v]==){cout<<(char)(v+'a');q.push(v);}
  28. }
  29. }
  30. for(int i=;i<;i++) if(in[i]==-)cout<<(char)(i+'a');
  31. }
  32. int main()
  33. {
  34. cin>>n;
  35. if(n==){for(char c='a';c<='z';c++) cout<<c;return ;}
  36. for(int i=;i<=n;i++)
  37. cin>>s[i];
  38. memset(in,-,sizeof(in));
  39. for(int i=n;i>=;i--)for(int j=i-;j>=;j--)
  40. {
  41. int l=;
  42. while(s[i][l]==s[j][l]&&l<=min(s[i].length(),s[j].length())) l++;
  43. if(l==s[i].length())
  44. {
  45. cout<<"Impossible"<<endl;
  46. return ;
  47. }
  48. if(l==s[j].length())continue;
  49. mp[s[i][l]-'a'][s[j][l]-'a']=;
  50. if(in[s[j][l]-'a']==-)in[s[j][l]-'a']=;
  51. in[s[i][l]-'a']+=in[s[i][l]-'a']==-?:;
  52. graph[s[j][l]-'a'].push_back(s[i][l]-'a');
  53. }
  54. for(int k=;k<;k++)
  55. for(int i=;i<;i++)
  56. for(int j=;j<;j++)
  57. mp[i][j]+=mp[i][k]*mp[k][j];
  58. for(int i=;i<;i++)
  59. if(mp[i][i]){cout<<"Impossible"<<endl;return ;}
  60. toposort();
  61. return ;
  62. }

510C的更多相关文章

  1. (CodeForces 510C) Fox And Names 拓扑排序

    题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...

  2. CodeForces 510C Fox And Names (拓扑排序)

    <题目链接> 题目大意: 给你一些只由小写字母组成的字符串,现在按一定顺序给出这些字符串,问你怎样从重排字典序,使得这些字符串按字典序排序后的顺序如题目所给的顺序相同. 解题分析:本题想到 ...

  3. codeforce 510C Fox And Names(拓扑排序)

    Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  4. 【codeforces 510C】Fox And Names

    [题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...

  5. Codeforces 510C (拓扑排序)

    原题:http://codeforces.com/problemset/problem/510/C C. Fox And Names time limit per test:2 seconds mem ...

  6. Linux下多任务间通信和同步-信号

    Linux下多任务间通信和同步-信号 嵌入式开发交流群280352802,欢迎加入! 1.概述 信号是在软件层次上对中断机制的一种模拟,是一种异步通信方式.信号可以直接进行用户空间进程和内核进程之间的 ...

  7. Codeforces510 C. Fox And Names

    Codeforces题号:#510C 出处: Codeforces 主要算法:判环+拓扑 难度:4.2 思路分析: 要是把这道题联系到图上就很容易想了. 如何建图?由于最后要求名字满足字典序,所以不妨 ...

  8. 专题:CF图论杂题

    题目是来自HZW的博客(构造题我是各种不会...) Solved 1 / 1 A CodeForces 500A New Year Transportation Solved 1 / 1 B Code ...

  9. 【操作系统】总结五(I/O管理)

    输入输出管理本章主要内容: I/O管理概述(I/O控制方式.I/O软件层次结构)和I/O核心子系统(I/O调度概念.局速缓存与缓冲区.设备分配与回收.假脱机技术(SPOOLing)). 5.1 I/O ...

随机推荐

  1. Application中的路径

    前提条件 项目工程目录:E:/Work/cosmosbox/cb-client/ 我电脑当前的用户名:qingqing PersistentDataPath Application.persisten ...

  2. 已Access为支持,书写一个C#写入的记录的方案

      /// <summary> /// 读取Excel文档 /// </summary> /// <param name="Path">文件名称 ...

  3. java 27 - 7 反射之 通过反射越过泛型检查

    之前学过的集合里面都有泛型,规定了泛型的类型以后,就不能往这个集合添加除了这个类型之外的类型数据了. 那么,有什么方法可以越过这个泛型,添加特定类型以外的类型数据么? 例子:  往ArrayList& ...

  4. Linux—C内存管理

    程序(可执行文件)存储结构与进程存储结构: 查看文件基本情况:file fileName.查看文件存储情况:size fileName(代码区text segment.全局初始化/静态数据区data ...

  5. [转]nodejs npm常用命令

    FROM : http://www.cnblogs.com/linjiqin/p/3765772.html npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准.有了n ...

  6. 1003. Emergency

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  7. C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值

    关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using Sy ...

  8. JS使构造函数与new操作符无关

    function User(name, passwordHash) { this.name = name; this.passwordHash = passwordHash; } 当使用User函数创 ...

  9. "org.jboss.netty.internal.LoggerConfigurator".DESCRIBED is already registered 的解决办法

    今天在jboss 6.2 EAP上部署一个项目时,报以下错误: org.jboss.msc.service.DuplicateServiceException: Service jboss.pojo. ...

  10. Windows 8的本地化应用程序清单

    I need to localize some data in application manifest (like name, description, splashscreen images et ...