天梯赛习题
fei头一只
这个作者很懒,什么都没留下…
展开
-
PTA 天梯赛练习集L1-002 打印沙漏 (解决方案)
解题思路: 观察图像可得以下结论: 1.能构成沙漏的数字有: 7、17、31、49...... 2.前后每个构成沙漏的大数减小数的差值为等差数列:10、14、18、22..... 此等差数列的前n项和公式为8*n+2*n*n; 因此根据数学关系可得任意两个沙漏的数值差为它们之间的等差数值的加和。 根据数学知识可得第n个(n初值取1)构成沙漏的数的表达式为8*n+2*n*n+7。 因此在程序中可以利用循环语句找到与输入个数最接近的沙漏数。 将此沙漏拆分为上下两部分进行输出,注意循环条件。原创 2021-11-10 00:31:02 · 609 阅读 · 0 评论 -
7-126 清点代码库
#include<iostream> #include<map> #include<vector> #include<algorithm> using namespace std; vector<int>code[10000]; typedef struct { int num; vector<int>v; }cc; bool cmp(cc e,cc r) { if(e.num!=r.num)return e.num>r.原创 2022-03-13 19:47:33 · 379 阅读 · 0 评论 -
7-70 树的遍历
#include<iostream> #include<vector> #include<queue> using namespace std; int hhh[45]; int zzz[45]; struct { int left; int right; }tree[91]; int build(int el,int er,int ml,int mr) { if(el>er||ml>mr)return 0; int root=hhh[er]; .原创 2022-03-09 21:02:33 · 73 阅读 · 0 评论 -
出栈序列的合法性
给定一个最大容量为M的堆栈,将N个数字按 1, 2, 3, ...,N的顺序入栈,允许按任何顺序出栈,则哪些数字序列是不可能得到的?例如给定M=5、N=7,则我们有可能得到{ 1, 2, 3, 4, 5, 6, 7 },但不可能得到{ 3, 2, 1, 7, 5, 6, 4 }。 输入格式: 输入第一行给出 3 个不超过 1000 的正整数:M(堆栈最大容量)、N(入栈元素个数)、K(待检查的出栈序列个数)。最后K行,每行给出N个数字的出栈序列。所有同行数字以空格间隔。 输出格...原创 2022-04-01 13:42:46 · 532 阅读 · 0 评论