注意前导零的消去. #include <iostream> #include <string> #include <sstream> #include <algorithm> using namespace std; +]; int n; bool cmp(const string &a, const string &b) { return a+b<b+a; } int main() { cin>>n; ;i<=n;i…
题意: 输入一个正整数N(<=10000),接下来输入N个字符串,每个字符串包括至多8个字符,均为数字0~9.输出由这些字符串连接而成的最小数字(不输出前导零). trick: 数据点0只包含没有0的串. 数据点2,5,6包含最小串全部为0且次小串含有前导零的数据. 如果所有的数字均为0,输出一个0即可. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std;…
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87},…
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-0229-87 or 0…
题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a collection of number segments, you are supposed to recover the smallest numb…
题目 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 difere…
题目 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 diff…
题目例如以下: 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 d…
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…
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 differe…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789138.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 题意:给出n个数,求拼接后值最小的数是多少. 一开始就简单的把所有字符串先从小到大拍个序,然后拼接起来去掉前导零,结果发现有个问题,比如下面两个32 32321如果按常规字符串比较,32是在32321前面.然而,32321-32才是较小的方案如何有个好的比较…
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87},…
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-0229-87 or 022…
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-0229-87 or 022…
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-0229-87 or 022…
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit…
https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 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 number…
题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323.   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 rec…
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 differe…
#include <iostream> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; bool mycmp(const string& a, const string& b) { string ta = a + b; string tb = b + a; int len = ta.length(); ; i<len; i++)…
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons…
http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you a…
简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOMER_MAX 1000+1 #define INF 0x6fffffff #ifndef LOCAL // #define LOCAL #endif LOCAL int n; // number of windows <=20 int m ;// queue capacity <=10 int k;…
因为是要构造完全二叉树,所以树的形状已经确定了. 因此只要递归确定每个节点是多少即可. #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<string> #include<stack> #include<map> #include<algorithm> using…
简单DFS #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<algorithm> using namespace std; +; vector<int>Tre…
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<string> #include<queue> #include<stack> #include<algorithm> #include<iostream> using namespace st…
一.技术总结 此问题是贪心类问题,给出可能有前导零的数字串,将他们按照某个顺序拼接,使生成的数最小. 解决方案,就是使用cmp函数,因为两两字符串进行拼接,进行排序从小到大. 拼接过后会有0可能出现在最前面,需要借助s.erase(s.begin())进行去除字符串前面的'0'字符,如果是字符串长度不为0,然后第一个字符为'0',去除,最后进行判断去除后是否为空,如果是则直接输出0,如果不是那么输出拼接后的字符串. 从这题可以得知,字符串拼接后也可以直接进行比较大小.拼接直接使用+号 去除字符串…
Source: PAT A1038 Recover the Smallest Number (30 分) Description: 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…
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 differe…
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性表:栈,队列,链表,顺序表 树:二叉树的建立,二叉树的遍历,完全二叉树,二叉查找树,平衡二叉树,堆,哈夫曼树 图:图的存储和遍历 经典高级算法: 深度优先搜索,广度优点搜索,回溯剪枝 贪心,并查集,哈希映射 最短路径(只考察过单源),拓扑排序(18年9月第一次涉及相关概念,未正式考过),关键路径(未…