510C
510C
拓扑排序:将那些受影响的字母拓扑排序,其后的输出
- #include<iostream>
- #include<cstdio>
- #include<vector>
- #include<queue>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- queue<int>q;
- int n;
- vector<int>graph[];
- string s[];
- int mp[][];
- int in[];
- void toposort()
- {
- for(int i=;i<;i++)
- if(!in[i])
- {cout<<(char)(i+'a');q.push(i);}
- // if(!flag){cout<<"Impossible"<<endl;return;}
- while(!q.empty())
- {
- int u=q.front();q.pop();
- for(int i=;i<graph[u].size();i++)
- {
- int v=graph[u][i];
- in[v]--;
- if(in[v]==){cout<<(char)(v+'a');q.push(v);}
- }
- }
- for(int i=;i<;i++) if(in[i]==-)cout<<(char)(i+'a');
- }
- int main()
- {
- cin>>n;
- if(n==){for(char c='a';c<='z';c++) cout<<c;return ;}
- for(int i=;i<=n;i++)
- cin>>s[i];
- memset(in,-,sizeof(in));
- for(int i=n;i>=;i--)for(int j=i-;j>=;j--)
- {
- int l=;
- while(s[i][l]==s[j][l]&&l<=min(s[i].length(),s[j].length())) l++;
- if(l==s[i].length())
- {
- cout<<"Impossible"<<endl;
- return ;
- }
- if(l==s[j].length())continue;
- mp[s[i][l]-'a'][s[j][l]-'a']=;
- if(in[s[j][l]-'a']==-)in[s[j][l]-'a']=;
- in[s[i][l]-'a']+=in[s[i][l]-'a']==-?:;
- graph[s[j][l]-'a'].push_back(s[i][l]-'a');
- }
- for(int k=;k<;k++)
- for(int i=;i<;i++)
- for(int j=;j<;j++)
- mp[i][j]+=mp[i][k]*mp[k][j];
- for(int i=;i<;i++)
- if(mp[i][i]){cout<<"Impossible"<<endl;return ;}
- toposort();
- return ;
- }
510C的更多相关文章
- (CodeForces 510C) Fox And Names 拓扑排序
题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...
- CodeForces 510C Fox And Names (拓扑排序)
<题目链接> 题目大意: 给你一些只由小写字母组成的字符串,现在按一定顺序给出这些字符串,问你怎样从重排字典序,使得这些字符串按字典序排序后的顺序如题目所给的顺序相同. 解题分析:本题想到 ...
- codeforce 510C Fox And Names(拓扑排序)
Fox And Names time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 【codeforces 510C】Fox And Names
[题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...
- Codeforces 510C (拓扑排序)
原题:http://codeforces.com/problemset/problem/510/C C. Fox And Names time limit per test:2 seconds mem ...
- Linux下多任务间通信和同步-信号
Linux下多任务间通信和同步-信号 嵌入式开发交流群280352802,欢迎加入! 1.概述 信号是在软件层次上对中断机制的一种模拟,是一种异步通信方式.信号可以直接进行用户空间进程和内核进程之间的 ...
- Codeforces510 C. Fox And Names
Codeforces题号:#510C 出处: Codeforces 主要算法:判环+拓扑 难度:4.2 思路分析: 要是把这道题联系到图上就很容易想了. 如何建图?由于最后要求名字满足字典序,所以不妨 ...
- 专题:CF图论杂题
题目是来自HZW的博客(构造题我是各种不会...) Solved 1 / 1 A CodeForces 500A New Year Transportation Solved 1 / 1 B Code ...
- 【操作系统】总结五(I/O管理)
输入输出管理本章主要内容: I/O管理概述(I/O控制方式.I/O软件层次结构)和I/O核心子系统(I/O调度概念.局速缓存与缓冲区.设备分配与回收.假脱机技术(SPOOLing)). 5.1 I/O ...
随机推荐
- Application中的路径
前提条件 项目工程目录:E:/Work/cosmosbox/cb-client/ 我电脑当前的用户名:qingqing PersistentDataPath Application.persisten ...
- 已Access为支持,书写一个C#写入的记录的方案
/// <summary> /// 读取Excel文档 /// </summary> /// <param name="Path">文件名称 ...
- java 27 - 7 反射之 通过反射越过泛型检查
之前学过的集合里面都有泛型,规定了泛型的类型以后,就不能往这个集合添加除了这个类型之外的类型数据了. 那么,有什么方法可以越过这个泛型,添加特定类型以外的类型数据么? 例子: 往ArrayList& ...
- Linux—C内存管理
程序(可执行文件)存储结构与进程存储结构: 查看文件基本情况:file fileName.查看文件存储情况:size fileName(代码区text segment.全局初始化/静态数据区data ...
- [转]nodejs npm常用命令
FROM : http://www.cnblogs.com/linjiqin/p/3765772.html npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准.有了n ...
- 1003. Emergency
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义控件编辑属性值
关于PropertyGrid控件的详细用法请参考文献: 1.C# PropertyGrid控件应用心得 2.C#自定义PropertyGrid属性 首先定义一个要在下拉框显示的控件: using Sy ...
- JS使构造函数与new操作符无关
function User(name, passwordHash) { this.name = name; this.passwordHash = passwordHash; } 当使用User函数创 ...
- "org.jboss.netty.internal.LoggerConfigurator".DESCRIBED is already registered 的解决办法
今天在jboss 6.2 EAP上部署一个项目时,报以下错误: org.jboss.msc.service.DuplicateServiceException: Service jboss.pojo. ...
- Windows 8的本地化应用程序清单
I need to localize some data in application manifest (like name, description, splashscreen images et ...