博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sorting It All Out (拓扑排序+思维)
阅读量:5009 次
发布时间:2019-06-12

本文共 2357 字,大约阅读时间需要 7 分钟。

An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C, D implies that A < B, B < C and C < D. in this problem, we will give you a set of relations of the form A < B and ask you to determine whether a sorted order has been specified or not.

Input

Input consists of multiple problem instances. Each instance starts with a line containing two positive integers n and m. the first value indicated the number of objects to sort, where 2 <= n <= 26. The objects to be sorted will be the first n characters of the uppercase alphabet. The second value m indicates the number of relations of the form A < B which will be given in this problem instance. Next will be m lines, each containing one such relation consisting of three characters: an uppercase letter, the character "<" and a second uppercase letter. No letter will be outside the range of the first n letters of the alphabet. Values of n = m = 0 indicate end of input.

Output

For each problem instance, output consists of one line. This line should be one of the following three: 
Sorted sequence determined after xxx relations: yyy...y. 
Sorted sequence cannot be determined. 
Inconsistency found after xxx relations. 
where xxx is the number of relations processed at the time either a sorted sequence is determined or an inconsistency is found, whichever comes first, and yyy...y is the sorted, ascending sequence. 

Sample Input

4 6A

Sample Output

Sorted sequence determined after 4 relations: ABCD.Inconsistency found after 2 relations.Sorted sequence cannot be determined. 代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
const int maxn=1e5+5;typedef long long ll;using namespace std;vector
vec[30];int n,m;int du[30];int chu[30];int du1[30];int flag;vector
ans1;void Tpsort(){ priority_queue
,greater
>q; priority_queue
q1; int s=0; for(int t=0;t
ans,ans2; while(!q.empty()) { int now=q.top(); int now2=q1.top(); q.pop(); q1.pop(); ans.push_back(now); ans2.push_back(now2); for(int t=0;t
>n>>m) { if(n==0&&m==0) { break; } for(int t=0;t

 

转载于:https://www.cnblogs.com/Staceyacm/p/11261298.html

你可能感兴趣的文章
oracle连接问题ORA-00604,ORA-12705
查看>>
NOI 2019 退役记
查看>>
java的几个日志框架log4j、logback、common-logging
查看>>
Java从零开始学十三(封装)
查看>>
Python2和Python3中的rang()不同之点
查看>>
MySQL的外键,修改表,基本数据类型,表级别操作,其他(条件,通配符,分页,排序,分组,联合,连表操作)...
查看>>
UVALive 4128 Steam Roller 蒸汽式压路机(最短路,变形) WA中。。。。。
查看>>
记忆--1.致我们不可缺少的记忆
查看>>
lintcode28- Search a 2D Matrix- easy
查看>>
react项目
查看>>
C# 万年历 农历 节气 节日 星座 星宿 属相 生肖 闰年月 时辰(转)
查看>>
A Simple Tree Problem
查看>>
Modular Inverse [ZOJ 3609]
查看>>
MySQL性能测试工具之mysqlslap使用详解
查看>>
深入理解jsonp跨域请求原理
查看>>
regsvr32注册COM组件失败
查看>>
jmeter,CSV数据加载、数据库连接、正则
查看>>
(独孤九剑)--正则表达式
查看>>
MySQL学习点滴 --分区表
查看>>
4.6.1 测试基础
查看>>