UVa 200 Rare Order (拓扑排序)

uva 200~299 22道题解 均accept 均accept,绝对实用,题目较多不一一点出 立即下载

200 - Rare Order

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=136


题意:给一列单词,这些单词是按一种未知的字典顺序排列的,要求输出这些字母的顺序。


思路:很明显,拓扑排序。

注意最后要多输出一个换行,否则会WA!


完整代码:

/*0.016s*/

#include<bits/stdc++.h>
using namespace std;

list<int> l[27];
char last[25], now[25];
bool has[27], vis[27];
int ans[27], cnt;

void dfs(int i)
{
	vis[i] = true;
	if (l[i].size())
		for (list<int>::iterator iter = l[i].begin(); iter != l[i].end(); ++iter)
			if (!vis[*iter]) dfs(*iter);
	ans[cnt++] = i;
}

int main()
{
	int len, i;
	gets(last);
	has[last[0] & 31] = true;
	while (gets(now), now[0] != '#')
	{
		len = min(strlen(last), strlen(now));
		for (i = 0; i < len; ++i)
		{
			if (last[i] != now[i])
			{
				has[last[i] & 31] = has[now[i] & 31] = true;
				l[last[i] & 31].push_back(now[i] & 31);
				break;
			}
		}
		memcpy(last, now, sizeof(now));
	}
	for (i = 1; i < 27; ++i)
		if (has[i] && !vis[i]) dfs(i);
	for (i = cnt - 1; i >= 0; --i)
		putchar(ans[i] + 'A' - 1);
    putchar(10);///尝试加了个换行,就AC了,果然是我太年轻。。。
	return 0;
}

Shopee商品详情页反爬实战:手把手逆向x-sap-Ri和x-sap-Sec请求头加密 本文详细解析了Shopee商品详情页反爬机制中x-sap-Ri和x-sap-Sec请求头参数的加密逻辑,通过JS逆向技术手把手教你定位加密入口、分析哈希算法与对称加密实现,并提供完整实战案例和应对反爬策略的高级技巧,助力开发者突破电商平台数据采集难点。 阅读详情

相关推荐

深度学习二分类实战:用Python+Keras搞定基因表达数据预测(附完整代码)

本文详细介绍了如何使用Python和Keras构建深度学习模型进行基因表达数据的二分类预测。通过数据预处理、特征选择、神经网络构建及优化策略,特别针对小样本场景提供了调参技巧和模型解释方法。文章还包含完整的代码示例,帮助读者快速掌握深度学习在生物信息学中的应用。

weixin_30642561的博客 245

uva 200拓扑排序

// //  main.cpp //  ceshi // //  Created by 戴之阳 on 2016/11/. //  Copyright © 2016年 sky.dai. All rights reserved. // // //  main.cpp //  ceshi // //  Created by 戴

Dzy929076300的博客 614

MQTT与物联网平台(一):基础知识和设备接入物联网平台的实现(以华为云为例)

本文简单介绍了MQTT的基础知识和使用方法,以蓝牙WIFI双模芯片W801作为硬件设备,接入到华为云。

weixin_50622833的博客 1万+

uva 200 Rare Order 拓扑排序

题意:给若干行按了yi dia

vickey 710

WSL2 Ubuntu 22.04安装NVIDIA驱动避坑指南:从驱动版本选择到CUDA环境验证

本文详细介绍了在WSL2 Ubuntu 22.04中安装NVIDIA驱动和配置CUDA环境的完整流程,包括驱动版本选择、环境变量设置以及常见问题解决方案。通过本指南,用户可以避免常见的安装陷阱,确保GPU加速环境正确配置,适用于深度学习开发和CUDA编程。

weixin_28419039的博客 463

LabVIEW波形图表时间轴设置:三种方法实现横坐标显示日期时间

在数据采集与设备监控场景中,波形图表的横坐标默认显示采样点序号而非日期时间,这给工程师分析历史数据带来不便。理解时间标识(Timestamp)的本质——一个自1904年起算的双精度秒数,是解决问题的关键。时间轴设置既是显示格式问题,更是数据层与显示层的协同设计。通过属性节点动态生成刻度标签、将时间标识数组直接作为X轴数据、或使用波形数据(Waveform)类型绑定t0与dt,分别适用于固定点数显示、非等间隔事件记录和等间隔连续采样等不同需求。合理选择方案并注意缓冲区预分配与时间连续性处理,可让波形图表准确呈

weixin_33416697的博客 254

【uva-200】Rare Order(拓扑排序过的第一道)

题目大意: 输入一堆按新的字母排序从小到大排好的字符串,#作为结束。 求新的字母排序规则。思路: 不知道一共多少组所以两个两个比较咯。 注意dfs第一个得到的是最小的字母。 是反序的要用stack倒着输出。

UPUP&TOPTOP 374

用Python实现四叉树(quad tree)

import numpy as np #正方形类 class square: #lx、ly为左上角坐标(x对应行号,y对应列号),rx、ry为右下角坐标 def __init__(self,lx,ly,rx,ry): self.lx=lx self.ly=ly self.rx=rx self.ry=ry #检查该矩阵中是否满足条件 #参数:原矩阵,阈值 #返回值:布尔类型 def check(s

weixin_44164489的博客 5868

UVA 200 (拓扑排序)

没加换行引发的一场悲剧呀 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; #include&lt;cstring&gt; #include&lt;string&gt; #include&lt;map&gt; #include&lt;vector&gt; #include&lt;cmath&

兜率工的博客 335

65页PPT全面学习大型汽车集团企业IT信息化(管理架构、应用架构、技术架构)

订单到交付(OTD):借助ERP、MES、LES、SRM、QMS、APS等系统,实现财务与业务一体化、高级排产、生产过程自动化及供应链协同。- 数据标准化:数据标准化是企业信息化建设基石,包括制定统一业务解释和标准、维护管理流程、发布应用等,涉及数据统一定义、分类、编码等内容。- 大数据应用:汽车行业大数据应用涵盖生产、销售、售后等环节,如设备预见性保养、销量预测、质量预警等,提升企业运营效率和决策能力。- 策略明晰:明确C2M管理矩阵,包括供应商、采购、物流、制造、销售、财务等环节的策略。

cdfunlove的博客 1049

2025届程序技术类笔试题

希尔排序在直接插入排序的基础上进行了改进,它通过比较相距一定间隔的元素来进行,各轮比较所用的距离随着算法的进行而减小,直到只比较相邻元素的最后一轮排序为止。某人逆着水流的方向向岸边划船,每次行进前进x米后需要休息一下,休息期间船会自行倒退y米,每次休息后再次行进,前进距离缩短1/5,若起始距离岸边为m米,问:能否到达岸上,需要行进多少次才能上岸。直接插入排序的原理是将第i个元素插入前面i-1个已排好序的记录中,将比第i个元素大的记录依次向后移动一个位置,将第i个元素插入空位。第二轮相邻比较,后移2次。

博客 595

UVa 200 - Rare Order

题目:给你一些大写字母构成的序列,他们按照特殊的字典序给出,输出已知关系的字母顺序。 分析:图论,拓扑排序。利用dfs求拓扑排序,记录回来的时间戳,逆序输出即可。             因为是偏序关系,具有传递性,所以只要比较相邻两串即可。 说明:最后要加一个换行╮(╯▽╰)╭。#include #include #include #include #include #inclu

小白菜又菜 2396

常用元器件使用方法13:物理层接口芯片DP83848的使用方法

介绍: DP83848是以太网物理层接口芯片,具有多种型号,从便于焊接角度考虑LQFP-48封装较为合适,采用LQFP-48封装的芯片,有2种型号,分别为DP83848I和DP83848C,如下图所示。 其主要区别是使用温度不同,如下图所示。 这2种芯片芯片网上均有销售,按理说DP83848C价格应该更加便宜,实际不然,DP83848I的价格低于DP83848C,考虑或与芯片的出货量...

snmplink的博客 1万+

UVA200 LA5139 Rare Order【拓扑排序】

A rare book collector recently discovered a book written in an unfamiliar language that used the same characters as the English language. The book contained a short index, but the ordering of the item...

海岛Blog 642

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

uva 200 Rare Order (拓扑排序)

uva  200 - Rare Order  (拓扑排序) 先求出大小关系的邻接矩阵,然后拓扑排序 #include #include #include #include #include #include using namespace std; int a[30][30],degree[30]; vector ans; void input(){ i

炒饭君的博客 1224

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

UVa:200 Rare Order(拓扑排序)

题意:按序给你一些字符串,要你输出它们的字典序 思路:根据前后两个字符串第一个不同的字符来确定有向关系建图,拓扑排序就行了。 #include #include #include #include #include #include #include #include using namespace std; int main() { string str1

Fighting 1265

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

UVA-200 Rare Order 拓扑排序

Rare Order Time Limit:3000MS Memory Limit:Unknown 64bit IO Format:%lld & %llu [Submit] [Go Back] [Status] Description Rare Order A rare ...

weixin_33893473的博客 98

ACM UVa 算法题 #200 - Rare Order的解法

题目链接在这里:ACM UVa #200 - Rare Order本题的解法相对简单:对于输入的所有字符串,只需两两比较,每个字符串可以获得一个不等关系(或者无法获得),如:ZXYZXW可以知道Y 按照此种方法依次两两比较,可以获得多个不等关系。当有了不等关系之后,下一步是如何根据不等关系得到这些字符的Order。最有效的方法是拓扑排序(Topology Sort):首先对

张羿的优快云专栏 3865

UVa 200 Rare Order

这篇文章探讨了一个关于语言字母顺序推断的问题。题目给出了一组按某种特殊语言排序规则排列的字符串,要求根据这些字符串推导出该语言的字母顺序。作者提出了一种基于拓扑排序的解决方案,通过构建字符间的有向关系图并进行拓扑排序来确定字母顺序。文章详细介绍了算法思路、代码实现和复杂度分析,并强调了输入输出的处理方式。该方法高效可靠,能够正确处理题目给定的约束条件,最终输出符合要求的字母顺序。

寂静山林 325

uvaLive 5139 (world final 1990 - Washington) Rare Order

题意是给定一个字符串的排列规则,即这个排序是按照特定的字符排序排下来的,要求输出已经给出来的全部字符的排列顺序。这个题是用拓扑排序做的,首先将每两个字符串能得到的规则进行比较,然后得到一张有向图。然后寻找出度为0的,则为最小,然后删掉所有以此的出度。以此类推。这里因为只有字母,所以主要复杂度就在于全部字符的排列规则的判定。我用向量处理这里未知的字符串数量,用时惊人啊,不过还是1Y了。下面是代码。

qiueji的专栏 424

UVa OJ 题解索引

寂静山林 755

UVa 200题记录

小白菜又菜 1112
上一篇: UVa 11371 Number Theory for Newbies (water ver.)
下一篇: UVa 12261 High Score (贪心&“向左走,向右走”)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值