- 博客(554)
- 收藏
- 关注
原创 The beginning
Second, the beginning of the personal blog... Programming experience and project experience, subject practice process... Three years later, this blog must be filled with my sweat, and for me,
2016-07-28 09:33:08
800
原创 天梯赛 L3 重排链表
题目链接:点击打开链接思路:先根据题目信息找到原始链表,然后根据规则重排#include <bits/stdc++.h> using namespace std; int head; int data[100010],nex[100010]; int main(){ int n; cin >> head >> n; for(int i = 0;i <...
2018-04-25 21:09:36
807
原创 天梯赛 L2 图着色问题
题目链接:点击打开链接思路:颜色数不合法,直接不满足;当颜色数合法,对于每一个方案,判断图中每一条边是否满足要求即可#include <bits/stdc++.h> using namespace std; int uu[250010],vv[250010]; int color[505]; int main(){ int v,e,k; int x,y; scanf("%d%d%...
2018-04-14 20:24:58
748
原创 天梯赛 L2 点赞狂魔
题目链接:点击打开链接思路:STL set + 排序#include <bits/stdc++.h> using namespace std; string name[105]; int num[105]; double aver[105]; int cnt[105]; set<int> s; struct node{ int index,count; double a...
2018-04-14 20:15:49
801
原创 天梯赛 L2 部落
题目链接:点击打开链接思路:天梯赛#include <bits/stdc++.h> using namespace std; int fa[10000]; set<int> s1,s2; int find(int x){ return fa[x] = (fa[x] == x?x:find(fa[x])); } void merge(int a,int b){ int x...
2018-04-14 20:12:41
734
原创 天梯赛 L1 整除光棍
题目链接:点击打开链接思路:模拟除法运算#include <bits/stdc++.h> using namespace std; int main(){ int num; int temp = 0,cnt = 0; string s = ""; cin >> num; do{ cnt++; temp = temp * 10 + 1; s.append...
2018-04-14 20:10:46
641
原创 天梯赛 L1 阅览室
题目链接:点击打开链接思路:利用STL map即可#include <bits/stdc++.h> using namespace std; map<int,char> m1; map<int,int> m2; int main(){ int n; int cnt = 0; double sum = 0; int num; char op; int ...
2018-04-14 20:04:30
733
原创 天梯赛2018模拟赛 L1 宇宙无敌加法器
L1-3 宇宙无敌加法器(20 分)地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个 PAT 星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是 7 进制数、第 2 位是 2 进制数、第 3 位是 5 进制数、第 4 位是 10 进制数,等等。每一位的进制 d 或者是 ...
2018-04-14 20:01:54
386
原创 天梯赛2018模拟 L1 外星人的一天
L1-8 外星人的一天(15 分)地球上的一天是 24 小时。但地球上还有一些精力和勤奋度都远超一般人的大神级人物,他们的“一天”是以 48 小时为周期运转的,这种人被人们尊称为“外星人”。比如普通人的周一早 8:30 是外星人的周一早 4:15;普通人的周二早 9:21 是外星人的周一下午 4:40 —— 对外星人而言,一周的工作时间只有三天(即普通人的周一至周六),周日他们会蒙头大睡恢复体力,...
2018-04-14 19:45:21
549
原创 天梯赛L3 社交集群
题目链接:点击打开链接思路:并查集#include <bits/stdc++.h> using namespace std; map<int,int> m; vector<int> v; int fa[1005]; int find(int x){ return fa[x] = (fa[x] == x?x:find(fa[x])); } void merge...
2018-04-14 19:37:33
483
1
原创 天梯赛 L2 抢红包
题目链接:点击打开链接思路:注意一个坑就行,不光抢到红包的人有收获,一个人发掉的红包,要从自己的钱数里扣掉。#include <bits/stdc++.h> using namespace std; struct node{ int id,cnt; double money; node(int a,int b,double c):id(a),cnt(b),mon...
2018-04-14 19:21:48
529
原创 天梯赛 L2 链表去重
题目链接:点击打开链接思路:水题,模拟即可。#include <bits/stdc++.h> using namespace std; int head,data[100000],nex[100000]; vector<int> v1,v2; set<int> s; int main(){ int n,id; scanf("%d%d",&...
2018-04-14 19:15:56
442
原创 天梯赛 L3 二叉搜索树的结构
题目链接:点击打开链接思路:题目不难,就是麻烦一些,创建完二叉树后,读取陈述句判断即可。#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> using namespace std; int data[105...
2018-04-03 20:10:36
483
原创 天梯赛 L2 功夫传人
题目链接:点击打开链接思路:广搜,从祖师爷开始搜索,搜到得道者加上其功力值即可。#include <cstdio> #include <cstring> #include <vector> #include <queue> using namespace std; int n,add[100000]; double total,rate,mul,re...
2018-04-03 20:06:03
495
原创 天梯赛 L3 是否完全二叉搜索树
题目链接:点击打开链接思路:同PAT 甲级 1123 点击打开链接#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; int root,data[25],le[25],rig[25]; void add(int &...
2018-04-03 20:02:13
317
原创 天梯赛 L2 愿天下有情人都是失散多年的兄妹
题目链接:点击打开链接思路:反向建树,搜索两个人各自5层以内的祖先,看有没有交集即可。坑点是,一定要保存父母辈的信息,题目的测试用例有判断父母辈的能不能成为情侣......#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include &l...
2018-04-03 19:57:40
556
原创 天梯赛 L2 互评成绩
题目链接:点击打开链接思路:水题。#include <cstdio> #include <iostream> #include <algorithm> #include <vector> using namespace std; vector<double> v,re; int main(){ int n,k,m; double sc...
2018-04-03 19:38:51
412
原创 天梯赛 L2 列车调度
题目链接:点击打开链接思路:二分 + 贪心。用一个数组保存当前每条铁轨的最后一个列车的编号(编号递增),每添加进来一个编号为num新列车,二分查找当前每个铁轨上最后一个列车的编号,且是满足小于num的最大值,若找到,用num替换;若找不到,添加一条新铁轨,即把num加到数组最后。#include <cstdio> #include <stack> #include <...
2018-04-03 19:30:29
479
原创 天梯赛 L2 红色警报
题目链接:点击打开链接思路:每失去一个城市,判断连通分量是否增加,若增加,则发出红色警报。#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; int n,m,map[505][505]; int book[505]...
2018-04-03 19:03:11
447
原创 PAT甲级 1128 N Queens Puzzle
题目链接:点击打开链接思路:经典搜索,N皇后问题。#include <cstdio> #include <cmath> #include <cstring> #include <iostream> using namespace std; bool judge(int chess[],int loc){ for(int i = 0;i < l...
2018-04-03 18:52:36
384
原创 PAT甲级 1129 Recommendation System
题目链接:点击打开链接思路:水题,顺序处理更新即可。#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <set> #include <map> using namespace std; struct no...
2018-04-03 18:50:32
439
原创 PAT甲级 1130 Infix Expression
题目链接:点击打开链接思路:首先找到树根,然后根据给出的树的信息,进行中序遍历。需要注意的是括号何时输出的问题。#include <cstdio> #include <cstring> #include <iostream> using namespace std; string data[25]; int n,root,le[25],rig[25]; int ...
2018-04-03 18:46:54
377
原创 PAT 甲级 Subway Map
题目链接:点击打开链接思路:最短路径问题,两种做法。一,利用Dijkstra算法,做适当变形,求出相应路径。二,搜索,先bfs出出发点到所有站的最短距离,再利用dfs搜索出符合要求的目标路径。原文有句话要注意,“If the quickest path is not unique, output the one with the minimum number of transfers, which...
2018-04-02 22:21:56
559
2
原创 PAT甲级 1124 Raffle for Weibo Followers
题目链接:点击打开链接思路:水题......#include <cstdio> #include <cstring> #include <iostream> #include <set> using namespace std; set<string> se; int main(){ int m,n,s; string t; sc...
2018-04-02 22:05:09
294
原创 PAT甲级 1125 Chain the Ropes
题目链接:点击打开链接思路:简单贪心,利用STL的priority_queue实现。#include <cstdio> #include <cstring> #include <iostream> #include <cstdlib> #include <cmath> #include <queue> using namesp...
2018-04-02 21:53:58
451
原创 PAT甲级 1126 Eulerian Path
题目链接:点击打开链接思路:按照题目给出的定理判断即可,同时该定理比较重要,要熟记。#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; int degree[505]; int cnt,head[505]; int...
2018-04-02 21:39:03
326
原创 PAT甲级 1127 ZigZagging on a Tree
题目链接:点击打开链接思路:根据中序和后序遍历序列创建出相应的BST,然后利用层序遍历,加上一些小技巧,根据要求输出节点序列。#include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <vector> using namespace...
2018-04-02 21:19:20
616
原创 PAT 1123 Is It a Complete AVL Tree
题目链接:点击打开链接思路:先按照AVL树的建树规则创建一棵二叉搜索树,得到层序遍历后,判断是否为完全二叉树,完全二叉树的判断方法为:逐层遍历每个节点,当遇到一个空节点,若仍然有未遍历的非空节点,说明不是完全二叉树。#include <cstdio> #include <cstring> #include <iostream> #include <cmat...
2018-04-02 20:44:28
403
原创 PAT 1119 Pre- and Post-order Traversals
题目链接:点击打开链接思路:按照BST的前序遍历和后序遍历建树,在建树的过程中判断出该BST是否唯一。#include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; int pre[50],post[50]; int fla...
2018-04-02 20:31:17
353
原创 PAT甲级 1111 Online Map(最短路径的应用)
题目链接:点击打开链接思路:写的比较繁琐,利用dijkstra算法分别去求最短路径和最快路径,再按照要求输出即可。还写了一个搜索的版本,由于剪枝函数不够优化,复杂度过高,最后一个测试点超时,27分。#include <cstdio> #include <cstring> #include <iostream> #include <vector> #i...
2018-04-02 20:22:40
2058
原创 PAT甲级 1101 Quick Sort
题目链接:点击打开链接思路:先扫两遍序列(从左到右和从右到左),得到max[1,i]和min[i,n],若max[1,i] <= a[i] <= min[i,n],那么a[i]符合要求。#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>...
2018-04-02 20:09:21
408
1
原创 PAT 1140 Look-and-say Sequence
题目链接:点击打开链接思路:模拟即可#include <bits/stdc++.h> using namespace std; vector<int> v; int main(){ int n; string num; cin >> num >> n; for(int i = 1;i < n;i++){ int nex; str...
2018-04-02 19:58:52
420
原创 2017天梯赛决赛 L3-1 二叉搜索树的结构(模拟)
题目链接:点击打开链接思路:建树,存储相关信息(数值,左儿子,右儿子,父节点,深度)。对于每类询问,做相应判断即可。#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> using namespace std...
2018-03-11 20:30:13
983
1
原创 PAT 甲级 1135 Is It A Red-Black Tree
题目链接:点击打开链接题意:给出一棵二叉搜索树,判断是否为红黑树(一种二叉平衡搜索树)。思路:其实很简单,利用给出的前序遍历的顺序插入节点,可以直接建造出对应的二叉搜索树,再根据红黑树的特征去判断是否为红黑树。#include <cstdio> #include <cstring> #include <cmath> #include <iostream&g...
2018-02-22 20:17:38
566
原创 PAT 甲级 1134 Vertex Cover
题目链接:点击打开链接题意:给出图的信息,每次给出一个点的集合,判断是否图中每一条边至少附属于该集合中的一个顶点。思路:直接利用set存储给出的点的集合,每次判断所有的边即可。#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include &...
2018-02-22 19:50:26
448
原创 PAT 甲级 1133 Splitting A Linked List
题目链接:点击打开链接题意:重新排列链表,重排规则是:负数出现在非负数的前面;[0,k]出现在大于k的数的前面;同时,同类数字之间维持原顺序。思路:按照负数、[0,k]、大于k分三次把对应类别的数字挑出来即可,最后再整合。#include <cstdio> #include <iostream> #include <vector> using namespace...
2018-02-22 19:32:46
496
原创 PAT 甲级 1132 Cut Integer(字符串处理)
题目链接:点击打开链接题意:K位的整数Z,前K / 2位取为A,后K / 2位取为B,问Z是否能够被A * B除尽?思路:按照字符串分理出A、B,转化为整数后去判断即可。#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> using namespace...
2018-02-22 19:17:35
516
原创 PAT 1139 First Contact
题目链接:点击打开链接思路:分析可知,有以下几个问题要处理,一是如何存储整个关系网;二是如何快速判断两个人之间是否存在朋友关系;三是如何将每个询问相应的结果存储并排序。题目没什么难度,采取合适的数据结构去处理以上三个问题即可,就是有一些坑点要注意。七种方法(优化或不同方法):一:前向星存图;利用set<pair<int,int> >快速判断朋友关系;set<pair&...
2018-02-09 00:58:44
1223
原创 PAT 1138 Postorder Traversal(二叉树的存储和遍历)
题目链接:点击打开链接 题意:给出二叉树的前序和中序遍历,给出其后序遍历的第一个元素。 思路:根据前序和中序遍历的结果得到二叉树的具体构造,再进行后序遍历。 代码: #include #include #include using namespace std; int pre[50010],in[50010]; int lSon[50010],rSon[50010];//按照前序遍历
2018-02-06 21:14:32
805
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅