G - Sorting It All Out POJ - 1094

Matlab安装Embedded Coder Support Package for Texas Instruments C2000 Processors教程 Matlab安装Embedded Coder Support Package for Texas Instruments C2000 Processors 阅读详情

G - Sorting It All Out

 POJ - 1094 

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 6
A<B
A<C
B<C
C<D
B<D
A<B
3 2
A<B
B<A
26 1
A<Z
0 0

Sample Output

Sorted sequence determined after 4 relations: ABCD.
Inconsistency found after 2 relations.
Sorted sequence cannot be determined.

题意:给N个大写字母,m个关系,要你判断能不能唯一确定字母的顺序或出现矛盾;

开始一直wa看别人的代码跟自己的又没什么不同,其实是忘了某些细节问题。。。以后先别急着否定自己。。。

#include<iostream>
#include<cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>

using namespace std;
const int N =  77;
const int M = 100007;

char a[M], c[M], b, s[N];
int head[N], deg[N], deg_[N], en, flag;

struct Edge{
	int v, to;
}edge[M];

void addedge(int u, int v) {
	edge[en].v = v;
	edge[en].to = head[u];
	head[u] = en++;
}

void tuopupaixu(int n) {
	
	memcpy(deg, deg_, sizeof(deg_)); //开始忘了每次拓扑之后会改变度数。。 
	queue<int> q;
	for (int i = 0; i < n; ++i) {
		if (deg[i] == 0) {
			q.push(i);
			if (q.size() > 1) {
				flag = -1;
			}
		}
	}
	int count = n, k = 0;
	while (!q.empty()) {
		if (q.size() > 1) {
			flag = -1;
		}
		int now = q.front(); q.pop();
		s[k++] = now + 'A';
		--count;
		for (int i = head[now]; ~i; i = edge[i].to) {
			int v = edge[i].v;
			if (--deg[v] == 0) {
				q.push(v);
			}
		}
	}
	s[k] = '\0';
	for (int i = 0; i < n; ++i) {
		if (deg[i] > 0) {
			flag = 1;
			return;
		}
	}
	if (count > 0) {
		flag = -1;
	}

}

int main() {
	int n, m;
	while (~scanf ("%d %d", &n, &m) && (n+m)) {
		memset(deg_, 0, sizeof(deg_));
		memset(head, -1, sizeof(head));
		for (int i = 1; i <= m; ++i) {
			scanf (" %c%c%c", &a[i], &b, &c[i]);
		}
        flag = 0, en = 0; 
		for (int i = 1; i <= m; ++i) {
			//printf ("debug: %d %d\n", a[i] - 'A', c[i] - 'A');
			addedge(a[i]-'A', c[i]-'A');
			++deg_[c[i] - 'A'];
			flag = 0;
			tuopupaixu(n);
			if (flag == 1) {
				printf ("Inconsistency found after %d relations.\n", i);
				break;
			} else if (!flag){
				printf ("Sorted sequence determined after %d relations: %s.\n", i, s); 
				break;
			}
		}	
		if (flag == -1) {
			puts ("Sorted sequence cannot be determined.");
		}
	}
	
	return 0;
} 

 

别再买错磁铁了!手把手教你为TLE5012B/AS5047等磁编码器选配和安装径向充磁磁铁 本文详细解析了为TLE5012B/AS5047等磁编码器选配和安装径向充磁磁铁的关键要点。从充磁方向的物理本质到供应商沟通技巧,再到安装工艺的黄金法则,帮助工程师避免常见错误,确保磁编码器稳定工作。特别强调了径向充磁的重要性及验证方法,并提供了尺寸选择、温度特性和抗干扰设计的实用建议。 阅读详情

相关推荐

操作系统期末大题类型题解

额,OS主要这回考程序分析题,PV操作、生产者消费者啊,哲学家进餐问题,死锁问题啊,如何避免死锁,经典银行家算法,页面置换算法啥的,磁盘调度......总计还有很多,就不一一说了 PV操作 谈到PV操作,首先要了解什么是信号量,其实就是用来解决互斥与同步问题的,分为原语wait(S)和signal(S),也就是我们常说的PV操作,在这里给出王道上的概念 wait(S){ while(S>0) S=S-1; } signal(S){ S=S+1; } 记录型信号量

ZXxxiaoxuan的博客 802

P1347排序(Floyd传递闭包)

P1347排序(Floyd传递闭包)

向上的咸鱼blueblue的博客 316

ZYQN7000系列VxWorks驱动开发:VxWorks系统移植

文章目录ZYQN7000驱动开发:VxWorks系统移植1.硬件环境2.编译vsb和vip工程2.1修改设备树文件2.2添加调试打印组件3.选择uboot来启动VxWorks内核4.尝试在开发板上启动内核4.1 拷贝镜像和设备树至SD卡4.2开发板上电4.2.1 uboot成功启动4.2.2 启动VxWorks5.添加shell和cmd组件 ZYQN7000驱动开发:VxWorks系统移植 1.硬件环境 正点原子领航者开发板 2.编译vsb和vip工程 vsb和vip工程的编译过程可以参考之前的文章,htt

明故宫的记忆 5518

POJ1094

题目: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

Rebaccaminmin的博客 789

INCA基础教程

以软件自带Demo为例记录INCA学习过程,主要内容包括测量与标定。

yunqianrui的博客 6万+

【Lane】 Ultra-Fast-Lane-Detection 复现

引言 车道线检测源码复现以及训练自己的数据集 1 环境搭建 conda create -n lane python=3.7 conda activate lane # 激活环境 conda install pytorch torchvision cudatoolkit=10.1 -c pytorch pip install -r requirements.txt 2 下载项目源码 若在服务器上可以用指令下载,否则直接在网址中下载 git clone https://github.com/cfzd/U

qq_44703886的博客 2万+

POJ 1094 拓扑排序

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 im...

weixin_44757834的博客 271

【数字孪生与仿真技术】07:焊装生产线虚拟调试与PLC代码生成全流程实战:从数字孪生到智能优化

摘要:本文系统阐述焊装生产线虚拟调试与PLC代码自动化生成的完整技术体系,结合工业4.0背景下的智能制造需求,构建从离散事件仿真、机器人运动规划到PLC控制逻辑生成的全流程解决方案。通过MATLAB/Simulink平台实现焊装线物流仿真优化,采用遗传算法进行缓冲区容量配置,结合Stateflow状态机设计PLC控制逻辑,并利用PLC Coder生成西门子S7-1500兼容的ST代码。某车企焊装线应用案例显示,虚拟调试技术使调试周期缩短75%,OEE提升13.4%,年节约成本超$420万。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1838

POJ 1094 Sorting It All Out 拓扑排序

Description 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

旧时光 834

HarmonyOS应用开发者基础认证

B. 自定义组件:可复用的 UI 单元,可组合其它组件。D. 内置组件:ArkTS中默认内置的基本组件和布局组件,开发者可以直接调用,如Column、Text、Divider、Button等。E. 属性方法:用于组件属性的配置,统一通过属性方法进行设置,如fontSize()、width()、height()、color() 等。在Column和Row容器组件中,justifyContent用于设置子组件在主轴方向上的对齐格式,alignItems用于设置子组件在交叉轴方向上的对齐格式。

牛肉胡辣汤 3827

从地方政府网站抓取政务公开数据:Python爬虫技术详解

在本文中,我们通过具体实例介绍了如何使用Python编写爬虫,从地方政府门户网站抓取政务公开数据。我们使用了requestsSelenium等最新技术,结合SQLite数据库存储抓取的数据,最后使用matplotlib进行数据可视化分析。通过本项目,您可以掌握如何抓取政府网站的公开数据,并将其进行清洗、存储和分析。这些技术对于进行政府政策分析、公共服务分析等方面具有重要的实际意义。希望通过本文的介绍,您能够更好地理解政务数据抓取的流程和方法,并能在实际工作中运用这些技术进行数据采集和分析。

2201_76125261的博客 1713

POJ-1094 Sorting it All Out

一个字母,则入度加一,并把小的当成大的字母的一个的出度,如果有一个入度为0就输出,并把其其所有出度点减一个入度,循环n次,若一次循环出两个字母,则排序失败,但不跳出,因为一旦遇到了一次循环根本无法输出,则输入结束后输出Inconsistency found after t relations.,t为这条指令的序号(每输入一个指令就判断),当然,若当次就能判断顺序,...

weixin_33928467的博客 176

改进后的yolov8导出进行部署到rk3588上时,导出为onnx格式报错aten::fft_fft2算子不支持导出...如何解决?

🏆本文收录于《全栈Bug调优(实战版)》专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&&订阅!持续更新中,up!up!up!! 备注:部分问题/疑难杂症搜集于互联网。

**My Coding Family** 1813

poj1094 Sorting It All Out(传递闭包)

题目 poj1094 Sorting It All Out 题解 Floyd解决 传递闭包 若有A&lt;B,那么连边(A,B,1),即d[A][B]=1。 如果有A&lt;B,且B&lt;C,对应有d[A][B]=1,d[B][C]=1,在Floyd算法中,会使 d[A][C] |= d[A][B] &amp; d[B][C] ,所以d[A][C]=1。这就是传递闭包。 实现时,可以边输入...

A_Bright_CH的博客 424

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

POJ-1094 Sorting It All Out 解题报告

Description 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 sequenc

岁月流风、、 1432

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ 1094 Sorting It All Out【拓扑排序】

题目链接: http://poj.org/problem?id=1094 题意: 给定前n个字母的大小关系,问你是否 根据前xxx个关系得到上升序列 所有关系都无法确定唯一的一个序列 第xxx个关系导致出现环 分析: 此题坑略多。。。。 m大小没给!!这个很无语啊。。。数组开大点马上AC了。。。 无法确定序列必须最后判断。 一旦可以判断出上升序...

An55511的博客 131

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

poj 1094 Sorting It All Out 拓扑排序

题目:http://poj.org/problem?id=1094 题意:给定n个字母,和m个它们之间的偏序关系,判断是否可以排成一个全序序列,在第几条关系后能得出全序序列,或者得出有矛盾。否则最后输出无法判断 思路:拓扑排序,如果有环肯定无法排成全序序列。进行拓扑排序时,每次只能有一个点入度为0,否则无法判断。 #include #include #include #include

弱智就要多努力 496

【原】 POJ 1094 Sorting It All Out 拓扑排序 解题报告

http://poj.org/problem?id=1094 方法: 每加入一条边就进行一次拓扑排序,从而找到符合条件的最少边数 拓扑排序的基本思想就是依次找到图中入度为0的节点,将该节点和其对应的边删除,这样就使得它的邻接节点的入度-1。反复循环这样做直到所有节点都从图中删除(都被编上拓扑编号),或者因为有环所以还剩下某些节点未被删除 Descrip...

ajiaxi111111的博客 203

POJ - 1094 Sorting It All Out 【拓扑排序】

题目链接 http://poj.org/problem?id=1094 题意 给出n个点,m对关系 判断 是否能够有一个确定的排列,或者矛盾,或者没有确定的排列 思路 在代码下面的注释中 AC代码 #include <cstdio> #include <cstring> #include <ctype.h&...

banshen0201的博客 88

POJ 1094_Sorting It All Out

analysis 一开始看到这种传递性的题以为是tarjan,结果发现书上给的是Floyd传递闭包 对于不等式i<j,就让G[i][j]=1,其他情况G[i][j]=0 然后跑一次传递闭包,G数组里面就存好了在当前给出的不等式条件下的所有数之间的大小关系 如果存在G[i][j]=G[j][i]=0,说明不能确定大小关系 如果存在G[i][j]=G[j][i]=1,说明矛盾 至于输出方案数,...

AndrewLi的博客 251

POJ-1094-Sorting It All Out

链接:https://vjudge.net/problem/POJ-1094#author=TIMEpings 题意: 用小于号"<"来定义两元素之间的关系,并于一个没有重复元素的有序上升序列 从小到大地排列这些元素。比如说,序列A,B,C,D意味着A<B;B<C;C<D。在这个问题里,我们会给你一组形如"A<B"的关系,询问你有序序列的合法性或其本身。 思路:...

weixin_34080951的博客 137

POJ1094-Sorting It All Out

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 提示:拓扑排序这道题有隐含这一信息,每输入一对关系,如果判定有结果,则可以忽略后面输入数据,即使后面输入数据能...

ζёСяêτ - 小優YoU 9369

Sorting It All Out(POJ-1094)

Problem Description 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 ...

Alex_McAvoy的博客 419

Sorting It All Out POJ - 1094

1.floyd 求传递闭包 #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> using namespace std; int d[30][30]; int g[30][30]; int n,m; int st[30]; int check() { f...

weixin_45113721的博客 170

Sorting It All Out POJ - 1094 Floyd + 传递闭包 + 拓扑序

一、内容 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,...

Tizzi的博客 1269

POJ 1094 Sorting It All Out

Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23082   Accepted: 7978 Description An ascending sorted sequence of distinct values i...

weixin_34067102的博客 79
上一篇: E - Rank of Tetris HDU - 1811 (拓扑排序+并查集)
下一篇: I - Cow Contest POJ - 3660
nucleare
博客等级 码龄9年 4粉丝 149原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值