
PTA
文章平均质量分 57
Joey丶sunk
古今成大事者 不惟有超世之才 亦必有坚忍不拔之志
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PTA 7-2 列车调度(25 分) 25分代码
原来上升的序列需要相应长度的轨道转化一下也就是求最长上升子序列的长度,有多种方法,这里的是复杂度比较低的 O(nlgn)的(注:博客作为交流使用,切勿抄袭应付作业)#includeusing namespace std;const int maxn = 100000 + 7, INF = 0x7f7f7f7f;int n;int a[maxn], b[maxn]原创 2017-10-09 15:16:33 · 1848 阅读 · 0 评论 -
PTA 7-8(树) 修理牧场(25 分) 最优二叉树
最优二叉树问题把最小的两端拿出来连接后放入队列中,重复的上述操作,,用优先队列可以容易完成(注:博客作为交流使用,切勿抄袭应付作业)#include #include #include #include #include #include #include #include #include #include #include #include原创 2017-10-11 16:59:11 · 2964 阅读 · 0 评论 -
PTA 7-1 树的同构(25 分)25分代码 结构体保存结点
树 是否 同构写的有点长,但大多写一半另一半复制就行了这里不需要重新建树,因为是 2叉树比较简单,只需要判断每个结点的两个孩子是不是相同就行了,结构体储存(注: 博客作为交流使用,请勿抄袭应付作业)#include #include #include #include #include #include #include #include #incl原创 2017-10-28 11:00:29 · 1370 阅读 · 0 评论 -
PTA 7-11(图) 公路村村通(30 分) 最小生成树prim
最小生成树 prim 算法,注意判非联通#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PI acos(-1.0)#define in原创 2017-10-11 19:09:22 · 2182 阅读 · 0 评论 -
PTA 7-17(查找) 字符串关键字的散列映射(25 分) 25分代码
需要注意的就是冲突的处理那部分,数据结构课本上的知识,运用 平方探测法解决#include#include#include#include#include#includeusing namespace std;const int maxn = 1000000 + 7, INF = 0x7f7f7f7f, mod = 1e9+7;int n, m;string s;/原创 2017-10-16 21:01:37 · 2893 阅读 · 0 评论 -
PTA 7-1 是否同一棵二叉搜索树(25 分) 建树比较
利用二叉树性质建树,比较#includeusing namespace std;const int maxn = 1024 + 7;int n, m;int a[maxn], b[maxn];void build1() { memset(a, -1, sizeof a); for(int i = 0; i < n; ++i) { in原创 2017-11-20 15:10:18 · 1585 阅读 · 1 评论 -
PTA 7-2 是否完全二叉搜索树(30 分)
建树输出,并检查#includeusing namespace std;const int maxn = 2220000 + 7;int n, m, f;int a[maxn], b[maxn];void build1() { memset(a, -1, sizeof a); for(int i = 0; i < n; ++i) {原创 2017-11-20 15:22:13 · 2311 阅读 · 1 评论 -
7-21(排序) PAT排名汇总(25 分)
注:仅供交流使用,勿抄袭应付作业#includeusing namespace std;typedef long long ll;const int maxn = 30000+7, INF = 0x7f7f7f7f;int T, n;struct node { string s; int sc, id, st, fst;}a[maxn];bool原创 2017-12-09 15:41:32 · 4582 阅读 · 0 评论 -
6-1 循环单链表区间删除(15 分)PTA
//库函数头文件包含#include#include#include//函数状态码定义#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2typedef int Statu原创 2017-09-12 22:34:28 · 2614 阅读 · 7 评论 -
L1-046 整除光棍 (20 分)
直接大数,编译器不能用 ,手动写完直接过import java.math.BigInteger;import java.util.*;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); BigInteger a = in....原创 2019-03-22 10:51:40 · 164 阅读 · 0 评论 -
L2-024 部落 (25 分) 并查集
需要知道总人数和不想交部落数首先并查集,把每一组的人和在一起,然后两个set分别表示所有人id和部落代表的id#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1e4 + 7;int n;int f[maxn];vector<int&g...原创 2019-03-22 10:54:38 · 487 阅读 · 0 评论 -
L3-016 二叉搜索树的结构 (30 分) 数组形式
让每个数对应一个id,然后树上的结点ans[] 和左孩子结点ls[] ,右孩子结点rs[] :存这些id,遍历记录深度#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 100 + 7;map<int, int> mp;int ls[...原创 2019-03-22 11:04:20 · 424 阅读 · 0 评论 -
L2-023 图着色问题 (25 分) 简单dfs
简单dfs + 注意细节#include<bits/stdc++.h>//#include<iostream>//#include<algorithm>//#include<cstdio>//#include<string>using namespace std;typedef long long ll;co...原创 2019-03-22 11:06:20 · 392 阅读 · 0 评论 -
1001 害死人不偿命的(3n+1)猜想 (15 分) Java练习&PTA乙级
递归函数//package lxk;import java.math.BigInteger;import java.util.Scanner;public class Main { public static int work(int n, int res) { if(n == 1) return res; if(n%2 == 0) { return...原创 2019-04-11 10:34:06 · 244 阅读 · 0 评论 -
1002 写出这个数 (20 分) Java练习&PTA乙级
1. int 转 string2. string 遍历3. map使用//package lxk;import java.math.BigInteger;import java.util.HashMap;import java.util.Map;import java.util.Scanner;public class Main { pu...原创 2019-04-11 10:59:12 · 240 阅读 · 0 评论 -
PTA 7-3(队列) 银行业务队列简单模拟(25 分) 25分代码
。。(注: 博客作为交流使用,请勿抄袭应付作业)#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PI acos(-1.0)#defin原创 2017-10-11 16:56:37 · 6719 阅读 · 0 评论 -
PTA 7-19(排序) 寻找大富翁(25 分) 25分代码
优先队列自动排序优先队列是堆,复杂度 期望是 O(nlgn)#include#include#include#includeusing namespace std;int n, m;priority_queue, less > qu;void init() { scanf("%d %d", &n, &m); int x; for(原创 2017-10-11 16:49:39 · 2082 阅读 · 0 评论 -
PTA 7-1 根据后序和中序遍历输出先序遍历(25 分) 递归输出
递归==(注: 博客作为交流使用,请勿抄袭应付作业)#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long原创 2017-10-27 22:35:01 · 1939 阅读 · 1 评论 -
PTA 7-1 银行排队问题之单队列多窗口服务(25 分)25分代码 (小模拟)
银行排队问题直接模拟就好,错了一次,没看见超过60分的按60算#includeusing namespace std;const int maxn = 1000 + 7, INF = 0x7f7f7f7f;int n, k;int b[11] = {0};int cnt[11] = {0};struct node { int t, p; in原创 2017-10-09 22:06:56 · 7075 阅读 · 3 评论 -
PTA 7-18(查找) 新浪微博热门话题(30 分) 30分代码 (已更新)
很蛋疼,,实在测不出哪里错了还有 题目中说 保留前40个字符也错了,不处理就对了(怀疑这题有问题方法就是 map 映射(注:博客作为交流使用,切勿抄袭应付作业)#includeusing namespace std;typedef long long ll;const int maxn = 100000+7, INF = 0x7f7f7f7f;int原创 2017-10-11 10:53:37 · 4960 阅读 · 1 评论 -
PTA 7-4(队列) 银行排队问题之单窗口“夹塞”版(30 分) 30分代码
模拟一下(注:博客作为交流使用,切勿抄袭应付作业)#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PI acos(-1.0)#de原创 2017-10-10 18:40:22 · 3176 阅读 · 1 评论 -
PTA 7-15(查找) 航空公司VIP客户查询(25 分) 25分代码 哈希方法
本来用map 写的,死活超时,看来卡不过去只能哈希了这里还稍微优化了一下,其实每个 哈希后的值存个 vector 来表示他的原值也行(注: 博客作为交流使用,请勿抄袭应付作业)// #include#include#include#includeusing namespace std;const int maxn = 100000 + 7, INF = 0x原创 2017-10-19 16:15:46 · 3956 阅读 · 1 评论 -
PTA 7-9(树) 目录树(30 分) 30分代码 建树+输出
赤裸裸的建树然后输出需要注意的是 输出的顺序:先输出目录,在输出文件,,但这个划分使他题目给定的,而不是后面没有子文件来判定目录这样在输入的时候处理好就是了方法就是 利用结构体node 做一棵树的根结点,,vec 里面存他的子树结点(也就是另一棵树的根结点)(注: 博客作为交流使用,请勿抄袭应付作业)下面是 AC 代码:#includeus原创 2017-10-19 16:43:03 · 3763 阅读 · 3 评论 -
PTA 7-6(队列) 银行排队问题之单队列多窗口加VIP服务(30 分) 30分代码 大模拟
VIP , 题目也是 VIP 级别的 贼几把恶心前后写了 再删了重写了 3遍,换了三种方法,,,终于 AC 这种题 很练脑子,练思路 (建议 不看题解 即使花一天也要自己写出来)(注:博客作为交流使用,切勿抄袭应付作业)#includeusing namespace std;const int maxn = 1000 + 7, INF = 0x原创 2017-10-10 23:05:18 · 3304 阅读 · 0 评论 -
PTA 7-7(排序) Windows消息队列(25 分) 25分代码 优先队列
可能 PTA 的编译器有问题,,,cin 关流操作没有用,,改成scanf 之类的就不超时了优先队列是一种 堆,,插入时自动按优先级排序(注:博客作为交流使用,切勿抄袭应付作业)#include#include#include#include#include#includeusing namespace std;struct node { //stri原创 2017-10-10 23:28:17 · 762 阅读 · 0 评论 -
PTA 7-22(排序) 模拟EXCEL排序(25 分)25分代码 结构体排序
三种排序方式,结构体很容易实现要注意 sort 排序时 手写的 cmp 函数的使用规则;#include#include#include#include#include#includeusing namespace std;const int maxn = 100000 + 7;int n, c;struct node { int id, sc;原创 2017-10-10 23:46:49 · 3234 阅读 · 0 评论 -
PTA 7-20(排序) 奥运排行榜(25 分) 25分代码 结构体排序
按照4种方式排序每次查询都对四种方式分别查询然后比较(注:博客作为交流使用,切勿抄袭应付作业)#include#include#include#include#include#includeusing namespace std;const int maxn = 233;int n, m;struct node { int id;原创 2017-10-11 08:35:21 · 3525 阅读 · 0 评论 -
PTA 7-6(队列) 银行排队问题之单队列多窗口加VIP服务(30 分) 30分代码
VIP 题目 很恶心的强烈建议手动模拟 锻炼思维#includeusing namespace std;const int maxn = 1000 + 7, INF = 0x7f7f7f7f;int n, k, vip;int b[11] = {0};int cnt[11] = {0};struct node { int t, p, vi;原创 2017-10-11 08:39:22 · 3228 阅读 · 0 评论 -
PTA 7-22(排序) 模拟EXCEL排序(25 分) 25分代码
结构体排序 分别重构三种cmp函数就行了(注:博客作为交流使用,切勿抄袭应付作业)#include#include#include#include#include#includeusing namespace std;const int maxn = 100000 + 7;int n, c;struct node { int id, sc;原创 2017-10-11 08:43:20 · 2787 阅读 · 0 评论 -
PTA 7-7(排序) Windows消息队列(25 分) 25分代码 优先队列
cin 关流 那一套东西不管用,,超时换scanf#include#include#include#include#include#includeusing namespace std;struct node { //string name; char name[22]; int id; bool operator < (const n原创 2017-10-11 08:41:23 · 1601 阅读 · 0 评论 -
PTA 7-10(图) 旅游规划(25 分) 25分代码
最短路问题更新最短路径的时候考虑最小花费(注:博客作为交流使用,切勿抄袭应付作业)#includeusing namespace std;const int maxn = 500+7, INF = 0x7f7f7f7f;int n, m, fir, en;int u, v, l, h, cnt;int head[maxn], d[maxn], d1[maxn], v原创 2017-10-04 14:44:53 · 4277 阅读 · 2 评论 -
PTA 6-2 二叉树的遍历(25 分) 25分代码 (数组实现层次遍历)
前三个 中序 先序 后序遍历直接递归就可以了最后一个层次遍历 可以把每一层 用数组存起来,容易实现(注: 博客作为交流使用,请勿抄袭应付作业)/* 你的代码将被嵌在这里 */void InorderTraversal( BinTree BT ) { if(BT == NULL) return; InorderTraversal(BT->Left)原创 2017-10-27 21:53:32 · 4622 阅读 · 0 评论 -
PAT甲级_All
生活总是充满着痛苦和不甘一夜不眠生活还是要继续,考研要继续,刷题也要继续、从现在开始,把PAT甲级的题目全刷完,一方面相当于给自己做做笔记,反思一下问题另一方面跟考PAT的伙计们做交流,顺便刷一下访问量祝充满自信,一往无前,逢敌亮剑考研顺利...原创 2019-05-14 09:56:44 · 156 阅读 · 0 评论