1038 Recover the Smallest Number (30 point(s))

【10. Wi-Fi 通用模组-小米 IoT 平台-如何进行硬件调试】 调试APP功能:从米家服务器缓存读取设备状态,等同于米家APP 的环境,开发者使用该调试器可模拟用户使用设备的实际情况,即调试米家 App 中的扩展程序。- 调试固件:调试器从固件读取设备状态,用于调试设备模组固件的某个单项功能,开发者使用该调试器可针对性地调试设备的某个功能。小爱语控测试工具:如果当前产品可被小爱语控,则可以使用该工具调试语控效果。调试APP功能(云端缓存) 阅读详情

1038 Recover the Smallest Number (30 point(s))

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders of combinations of these segments, and the smallest number is 0229-321-3214-32-87.

Input Specification:

Each input file contains one test case. Each case gives a positive integer N (≤10​4​​) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the smallest number in one line. Notice that the first digit must not be zero.

Sample Input:

5 32 321 3214 0229 87

Sample Output:

22932132143287

思想:贪心策略 

题意:存在一组可能含有前导0的数字串,请问如何连接使得它的值尽可能的小。

由样例可以看出,不能直接排序并连接,如32、321中应当32132<32321,可以看出两个字符串之间的排序应当取决于它们拼接后的大小。采用这样一种贪心策略:对于S1 与 S2,如果 S1+S2 < S2 + S1,那么把 S1放在S2前面。将上述写到cmp函数中。

注意点:前导0的处理。

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(string a,string b){
	return a+b<b+a;
}
vector<string> s;
int main(void){
	int n;string str,ans;
	cin>>n;
	while(n--){
		cin>>str;
		s.push_back(str);
	}
	sort(s.begin(),s.end(),cmp);
	for(int i=0;i<s.size();i++) ans+=s[i];
	while(ans.size()>0&&ans[0]=='0') ans.erase(ans.begin());
	if(ans.size()==0) cout<<"0"<<endl;
	else cout<<ans<<endl;
	return 0;
}

 

PS2硬盘启动终极指南:从FMCB到OPL,告别光驱打造游戏博物馆 在计算机存储与数据读取领域,硬盘启动技术通过将操作系统或应用程序从本地硬盘直接加载,绕过了传统光驱等外部介质,实现了速度与可靠性的双重提升。其核心原理在于利用引导程序接管系统初始化流程,直接访问硬盘上的特定分区与文件镜像。这项技术的价值在于极大提升了数据读取效率、降低了物理介质损耗,并扩展了存储容量与管理的灵活性。在怀旧游戏硬件改造、嵌入式系统定制等场景中,硬盘启动技术被广泛应用,以实现老旧设备的功能焕新与性能优化。本文聚焦于索尼PS2游戏主机的硬盘启动方案,深入探讨了如何利用FMCB(Free MCBoo 阅读详情

相关推荐

斯坦福HumanPlus机器人核心技术解析:从HST强化学习框架到HIT模仿学习的实现路径

本文深入解析了斯坦福HumanPlus人形机器人的核心技术实现路径。其核心在于HST强化学习框架与HIT模仿学习架构的协同:HST作为“小脑”,通过rsl_rl框架在仿真中训练稳健的低级运动控制;HIT作为“大脑”,基于改进的Transformer架构学习高级任务规划。文章详细拆解了从算法原理、代码实现到硬件部署的全流程,为复现这一前沿机器人系统提供了实战指南。

weixin_29082143的博客 282

1038 Recover the Smallest Number (30 point(s)) - C语言 PAT 甲级

设计思路: 贪心算法: * 对数字串排序,按照相邻两个字符串组成的字符串大小排序: * 形似 return (a + b) < (b + a); * 这样排序后保证了每相邻两个子串组成的数字最小,保证了最终组成的数字最小; * 注意前导 0 的处理,若最终组成的数是 0,也要输出一个 0;

有三只土豆 371

家庭网络中,路由器和交换机的连接顺序

它的目的是给路由器增加端口,用户访问互联网的速度比情况一要快,常用于办公网络、家庭成员多的场景。光纤入户首先连接的肯定是光猫,而在光猫的后面,是先连接交换机?还是应该接路由器呢?家庭网络中路由器和交换机的先后连接顺序。它目的是让更多的用户访问互联网。常用于一些超大型机房、网吧等。至于路由器和交换机的区别。两者之间很多功能都有兼容。但用户上网速度相对较慢。在技术日益迭代的今天。

m0_74075744的博客 1万+

1038 Recover the Smallest Number (30point(s))

文章目录问题解决方法后记 问题 Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like ...

weixin_43725617的博客 212

PCIe(Peripheral Component Interconnect Express)的带宽和速率

PCIe带宽与速率解析 PCIe的速率指物理层传输速度(GT/s),而带宽是实际有效数据吞吐量(GB/s)。不同PCIe版本采用不同编码方式: PCIe 1.0-2.0:8b/10b编码(80%效率) PCIe 3.0+:128b/130b编码(≈98.5%效率) 单向峰值带宽速查(单位:GB/s): 版本 x1 x4 x8 x16 PCIe3 0.98 3.94 7.88 15.75 PCIe4 1.97 7.88 15.75 31.51 PCIe5 3.94 15.75 31.51 63.02 PCIe

MHD0815的博客 347

【unity实战】使用unity的Navigation+LineRenderer实现一个3D人物寻路提前指示预测移动轨迹的效果,并可以适配不同的地形

本文介绍了在Unity中使用Navigation导航系统和LineRenderer实现3D人物寻路轨迹预测效果的方法。通过NavMesh.CalculatePath计算路径点,结合Physics.Raycast进行地面点投射,将路径点赋予LineRenderer渲染出移动轨迹。关键点包括:1)利用NavMesh.CalculatePath计算两点间可行走路径;2)通过射线检测获取地面点提高路径适配性;3)使用协程定期更新路径绘制。文章还提供了完整代码实现,并说明需要将地面图层设置为Ground并进行导航网格

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 460

1038 Recover the Smallest Number (30)(30 point(s))

1038 Recover the Smallest Number (30)(30 point(s)) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we c...

Cute_jinx的博客 291

团体程序设计天梯赛竞赛题--登顶题【L3-039 攀岩】

登顶级 3 道题,每道题 30 分,满分为 90 分。

Pretty Boy Fox的博客 654

1038 Recover the Smallest Number

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229...

Godblessuam的博客 174

Winform从入门到精通(21)——ProgressBar(史上最全)

本介绍ProgressBar控件的详细用法,包含所有属性、事件,绝对史上最全!

qq_34059233的博客 3350

YOLOv11改进策略【注意力机制篇】| SE、CBAM、ECA、CA、Swin Transformer等注意力机制全面解析与应用

本文详细介绍了五种主流的注意力机制及其在YOLOv11中的应用。通过合理的模块选择和位置部署,注意力机制能够显著提升目标检测性能。

QQ_778132974的博客 877

1038 Recover the Smallest Number (30 point(s))

题解 找一个最小的排列。此题我是蒙的,没有证明。没看过sort的源码,有兴趣的可以去读一下sort源码可能就会知道缘由。 #include&lt;iostream&gt; #include&lt;string&gt; #include&lt;algorithm&gt; #include&lt;vector&gt; using namespace std; vector&lt;string...

徐伯莱 565

【3天快速入门WPF】1-从最简单的xaml开始

首先我们要知道xaml语法中声明即定义,意思就是“见到元素就相当于创建实例”,MainWindow.xaml的主干是一个元素里包含着一个 元素。这段程序就是在定义一个Window类的实例,这个实例的一个组成部分是一个Grid类的实例。

Zy100Papa的博客 1624

A 1038 Recover the Smallest Number (30 point(s)) ——string

题目考察:string用得熟练就成 原题: Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers suc...

a7701935的博客 164

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

PAT甲级 1038 Recover the Smallest Number (30 point(s))

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different ord

m0_51711089的博客 128

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

PAT(甲级)1038 Recover the Smallest Number (30point(s))

题目 题目链接 思路 题目大意:对一系列数进行恰当的排列,使其值最小; 主要是比较函数的书写比较难想,这里用到了string的比较,我们肯定想让 a + b < b + a,所以比较函数可以这样写; 另外,不能单独比较 a 和 b,因为在所有前导位都相同的情况下,长度短的肯定比长度长的要大; 代码 #include <iostream> #include <string> #include <cstring> #include <vector> #inc

hjyp的博客 166

深度学习工具包 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")

PAT (Advanced Level) Practice - 1038 Recover the Smallest Number(30 分)

题目链接:点击打开链接 题目大意:略。 解题思路:其实就是一个序的关系,所有的组合有n!种,(像"所谓组出最小数其实是获得字典序最小的拼接方式"这种废话我就不说了)。假设我们获得了其中的一个组合,然后又两个相邻的数字片段a,b。然后我们就要想,把a和b交换能不能使整个序列变小呢?这个问题的其实等价于b+a 是否小于a+b(此处"+"为连接符),也就是说对于这样一个序列,如果某两个相...

564

pat 1038 Recover the Smallest Number

这题明显是贪心的策略,但是排序算法一直没写好,费了我几个小时。后来发现,有个博客http://ppcool.iteye.com/blog/1731427 里面的排序好简单呀,好受打击。回宿舍继续舔伤口。 /* * pat_1038.cpp */ #include #include #include #include using namespace std; #define N 100

水人的专栏 2159

PTA甲级1038 Recover the Smallest Number (30分)

首先,先贴柳神的博客 https://www.liuchuo.net/ 这是地址 想要刷好PTA,强烈推荐柳神的博客,和算法笔记 题目原文 1038 Recover the Smallest Number (30分) Given a collection of number segments, you are supposed to recover the smallest number from...

Huangpengyu123的博客 195

1038. Recover the Smallest Number (30)

题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standa

Apie_CZX的专栏 1540

1038 Recover the Smallest Number (30 分)

1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover...

92377 741

1038. Recover the Smallest Number (30)好题

一道挺好的思想题

The Blog Of Uncle_Sugar 4103

1038 Recover the Smallest Number

1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recove...

lannister_awalys_pay的博客 188

[C++] PAT 1038 Recover the Smallest Number (30分)

Sample Input: 5 32 321 3214 0229 87 Sample Output: 22932132143287 题解: 参考了大佬的代码 1.以字符串接收数据, 2.之后对字符串数组进行排序,采用了贪心策略, 3.最后将字符串数组进行拼接为字符串s,得到最小的数, 4.注意是以非0开始,若s.length() == 0直接输出0 #include <iostream> #include <string> #include <algorithm&gt.

快乐de约定的博客 1995

1038 Recover the Smallest Number (30 分)

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0...

SourDumplings的博客 326
上一篇: 1037 Magic Coupon (25 point(s))
下一篇: 1091 Acute Stroke (30 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值