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的更多相关文章

  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. rqnoj28[stupid]愚蠢的宠物

    题目描述 背景 大家都知道,sheep有两只可爱的宠物(一只叫神牛,一只叫神菜).有一天,sheep带着两只宠物到狗狗家时,这两只可爱的宠物竟然迷路了…… 描述 狗狗的家因为常常遭到猫猫的攻击,所以不 ...

  2. IE8 HACK介绍

    1.‘\9’: eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\ ...

  3. Eclipse使用Maven构建web项目

    1.创建Maven项目: 点击“File”菜单,或者通过工具栏的“New”创建Project,如下图所示: 选择Maven->Maven Project,弹出向导对话框,如下图所示: 选中Cre ...

  4. UDP的坏处

    众所周知,UDP是一个面向无连接的协议.通信时不可靠的.这就会出现一些问题 (1)数据报丢失 因为是无连接,的所以可以用recvfrom和sendto来接收和发送消息,如果socket是阻塞的,那么当 ...

  5. 学习C++.Primer.Plus 6 分支语句和逻辑操作符

    ||. &&操作符是一个顺序点 < 操作符从左向右结合 ; < age < )//17<age为true, = 1,肯定 < 27.所以为整个条件为tru ...

  6. 扩展 easyui 控件系列:为datagrid 增加过滤行

    此功能还为真正完成,起到抛砖引玉的效果,发动大家的力量把这个功能完善起来,效果图如下: 基本上就是扩展了 datagrid.view 中的onAfterRender 这个事件,具体代码如下: $.ex ...

  7. Java的注解(Annotation)

    1.什么是注解 Annotation is code about the code, that is metadata about the program itself. Java注解,是Java5. ...

  8. 记 FineUI 官方论坛所遭受的一次真实网络攻击!做一个像 ice 有道德的黑客!

    在开始正文之前,请帮忙为当前 排名前 10 唯一的 .Net 开源软件 FineUI  投一票: 投票地址: https://code.csdn.net/2013OSSurvey/gitop/code ...

  9. [leetcode]算法题目 - Reverse Nodes in k-Group

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...

  10. 提高Visual Studio开发性能的几款插件

    通过打开Visual Studio,单机TOOLS—Extensions and Updates-Online-Visual Studio Gallery(工具-扩展和更新-联网-Visual Stu ...