![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PTA
氯的平方
大一新生,写点东西抗遗忘
展开
-
把头打烂都要记住的验证栈弹出序列
#include <iostream> #include <algorithm> #include <stack> #include <string> #include <vector> using namespace std; const int N = 1e6 + 10; int poped[N]; void solve(int n) { stack<int> help; vector<string> ans;原创 2020-11-15 21:46:18 · 53 阅读 · 0 评论 -
L2-001 紧急救援 (25分) 详细 dijskra算法 +最短路径打印
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。 输入格式: 输入第一行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市的编号为0 ~ (N−1);M是快速道路的条数;S是出发地的城市编号;D是目的地的城市编号。 第二行给出N个正整数,原创 2020-11-01 17:06:15 · 362 阅读 · 0 评论 -
7-3 根据后序和中序遍历输出先序遍历 (25分)
本题要求根据给定的一棵二叉树的后序遍历和中序遍历结果,输出该树的先序遍历结果。 输入格式: 第一行给出正整数N(≤30),是树中结点的个数。随后两行,每行给出N个整数,分别对应后序遍历和中序遍历结果,数字间以空格分隔。题目保证输入正确对应一棵二叉树。 输出格式: 在一行中输出Preorder:以及该树的先序遍历结果。数字间有1个空格,行末不得有多余空格。 输入样例: 7 2 3 1 5 7 6 4 1 2 3 4 5 6 7 输出样例: Preorder: 4 1 3 2 6 5 7 #include<原创 2020-10-30 20:39:35 · 1592 阅读 · 0 评论 -
逆波兰表达式 (中缀转换位后缀)
//#include <bits/stdc++.h> #include<map> #include<iostream> #include<stack> #include<vector> using namespace std; const int maxn = 1e4 + 10; typedef long long ll; stack<char> sta; // sta是用来存各种符号的(正负除外,正负号会作为数字的一部分和数字原创 2020-10-22 16:42:03 · 77 阅读 · 0 评论 -
L1-050 倒数第N个字符串 (15分)
L1-050 倒数第N个字符串 (15分) 最开始在判断一共有多少个字符串时就出现了错误,其实假如是3位的情况,aaa到zzz每个位置的字母都有机会出现a~z,所以直接可以判断为 pow(26,L) 个串,而不是最开始以为的L + LL + LL *L. #include<bits/stdc++.h> using namespace std; int main() { int L,N...原创 2020-02-27 15:04:37 · 136 阅读 · 0 评论 -
L1-049 天梯赛座位分配 (20分)
题目:PTA L1-049 #include<bits/stdc++.h> using namespace std; int num[111]; int pos[111][111][111]; int Max = 0,pre = 0;//pre设置为0表示为初始状态 int x; int main(void) { int n; scanf("%d",&n); for(i...原创 2020-02-26 22:02:54 · 111 阅读 · 0 评论 -
PTA L006连续因子
本来是考试题,结果拖了好久都懒得去想 : 题目: 给出代码: #include <iostream> #include <cmath> using namespace std; long int num, temp; int main(void) { cin >> num; int first = 0, len = 0, maxn = sqrt...原创 2019-12-05 22:43:36 · 110 阅读 · 0 评论