PTA
文章平均质量分 97
-skyline-
这个作者很懒,什么都没留下…
展开
-
哈夫曼编码
7-9 Huffman Codes(30 分)In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in the history of computer science. As a pr...转载 2018-05-25 21:08:39 · 16182 阅读 · 1 评论 -
求前缀表达式的值
7-1 求前缀表达式的值(20 分)算术表达式有前缀表示法、中缀表示法和后缀表示法等形式。前缀表达式指二元运算符位于两个运算数之前,例如2+3*(7-4)+8/4的前缀表达式是:+ + 2 * 3 - 7 4 / 8 4。请设计程序计算前缀表达式的结果值。输入格式:输入在一行内给出不超过30个字符的前缀表达式,只包含+、-、*、\以及运算数,不同对象(运算数、运算符号)之间以空格分隔。输出格式:输...转载 2018-05-25 21:08:57 · 27302 阅读 · 11 评论 -
笛卡尔树
7-4 笛卡尔树(20 分)笛卡尔树是一种特殊的二叉树,其结点包含两个关键字K1和K2。首先笛卡尔树是关于K1的二叉搜索树,即结点左子树的所有K1值都比该结点的K1值小,右子树则大。其次所有结点的K2关键字满足优先队列(不妨设为最小堆)的顺序要求,即该结点的K2值比其子树中所有结点的K2值小。给定一棵二叉树,请判断该树是否笛卡尔树。输入格式:输入首先给出正整数N(≤1000),为树中结...转载 2018-05-25 21:09:11 · 867 阅读 · 0 评论 -
PTA A1030 Travel Plan (Dijkstra求单源最短路+边权花费+打印路径)
法1:Dijkstra+pre数组+c数组#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXV=510;const int INF=0x3f3f3f3f;int G[MAXV][MAXV];bool vis[MAXV];i...原创 2019-03-08 16:51:13 · 179 阅读 · 0 评论 -
PTA A1003 Emergency (Dijkstra求单源最短路)
题意:给出n个城市,m条无向边。每个城市中都有一定数目的救援小组,所有边的边权已知。现在给出起点和终点,求从起点到终点的最短路径条数及最短路径上的救援小组数目之和。如果有多条最短路径,则输出数目之和最大的。#include<bits/stdc++.h>using namespace std;#define INF 0x3f3f3f3fconst int N=505;int...原创 2019-03-03 18:29:49 · 235 阅读 · 0 评论 -
PTA GPLT L1-039 古风排版
#include<bits/stdc++.h>using namespace std;int main(){ int n; cin>>n; getchar(); string s; getline(cin,s); int l=s.size(); int d=l%n;//补几个空格 if(d!=0) d=n-d;//取模的时候,永远记得考虑0 whil...原创 2019-03-08 20:12:03 · 123 阅读 · 0 评论 -
PTA A1020 Tree Traversals
#include<bits/stdc++.h>using namespace std;const int maxn=45;int in[maxn],post[maxn],Hash[maxn],n;//题目数据范围N<=30, Hash数组不能设成35!!! struct node{ int val; node* left; node* right; node(i...原创 2019-03-16 09:59:13 · 142 阅读 · 0 评论 -
PTA B1027 打印沙漏
输出题也可以写得如此优美2333#include<bits/stdc++.h>using namespace std;int a[1005];int main(){ int n; char ch; cin>>n>>ch; int i; --n; for(i=2;n-4*i+2>=0;++i){ //1 1 2 3 3 5 2*i-...原创 2019-03-16 10:15:57 · 225 阅读 · 0 评论