![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PAT
learner_cv
这个作者很懒,什么都没留下…
展开
-
1038. Recover the Smallest Number
比较喜欢这种题,代码不长,但是有意思。从别人那学习到的#include #include #include #include using namespace std;bool compare(const string &str1, const string &str2){ return str1+str2 < str2+str1;}int main(){原创 2016-06-24 16:43:55 · 238 阅读 · 0 评论 -
1099. Build A Binary Search Tree
构造树的结构,记录每个节点左右的孩子节点数,从而判断其数值的大小位置。#include #include #include #include using namespace std;struct Info{ int left; int leftNodes; int right; int rightNodes; int total;原创 2016-06-23 15:56:25 · 232 阅读 · 0 评论 -
1064. Complete Binary Search Tree
网上学习的别人的代码重点:递归,完全二叉树的性质#include #include #include using namespace std;int *tree;int *num;int n;int pos;void build(int root){ if(root > n) return; build(root*2); tre原创 2016-06-23 10:40:15 · 258 阅读 · 0 评论 -
1065. A+B and C (64bit)
在网上学习的别人的代码重点:判断是否溢出#include #include using namespace std;/* maximum signed long long int value */#define LLONG_MAX 9223372036854775807/* minimum signed long long int value */#define LLO原创 2016-06-23 09:56:44 · 269 阅读 · 0 评论 -
1024. Palindromic Number
字符串判断回文,可先用reverse将其转置,然后判断是否相等#include #include #include using namespace std;string myadd(const string &str1, const string &str2){ int i = str1.length()-1; int j = str2.length()-1;原创 2016-06-17 09:12:15 · 262 阅读 · 0 评论 -
1030. Travel Plan
增加了路径,记录从哪一个点过来的,其余同1003题一样#include #include #include #include using namespace std;int n,m,c1,c2;int **roadcost;int **road;int *resultpath;int roadlen = INT_MAX;int totalcost = 0;void D原创 2016-07-02 21:57:18 · 234 阅读 · 0 评论 -
1003. Emergency
注意最后输出的是最短路径的条数,不是距离。。。用dfs解决#include #include #include #include using namespace std;int n,m,c1,c2;int *rescueteam;int **road;int roadlen = INT_MAX;int totalteam = 0;int cnt;void DFS(原创 2016-07-02 19:25:45 · 283 阅读 · 0 评论 -
1076. Forwards on Weibo
DFS有2个用例一直过不了,BFS又很神奇的死活都不对。。。跪了。。照着别人的改的#include #include #include #include #include using namespace std;struct Node{ int level; list followers;};Node *users;int n, level;//BFS原创 2016-07-02 17:01:31 · 273 阅读 · 0 评论 -
1045. Favorite Color Stripe
变种最长公共子序列,自己画个数组算一下就知道过程了#include #include #include using namespace std;int main(){ int n; int m; int *eva; int l; int *stripe; int **maxcomm; cin >> n; cin >>原创 2016-07-01 20:17:26 · 338 阅读 · 0 评论 -
1013. Battle Over Cities
并查集,先将路径存储下来,每次考虑一个城市的时候,在路径集合中跳过与该城市相连的边,判断此时有几个集合(未考虑的这个城市单独为一个集合)#include #include #include #include using namespace std;struct Edge{ int v1; int v2;};int n, m, k;int findRoot(原创 2016-07-23 23:44:20 · 197 阅读 · 0 评论 -
1052. Linked List Sorting
测试用例很坑。注意链表为空的情形,并且可能有孤节点。#include #include #include #include #include using namespace std;struct Node{ int addr; int value; int next; int tag;};bool compare(const Node &s1原创 2016-06-13 21:48:54 · 257 阅读 · 0 评论 -
1066. Root of AVL Tree
终于主动写了一次AVL树。。。果然还是有点晕这是学习了别人的,照着改的#include #include using namespace std;struct Node{ int value; int height; Node *left; Node *right; Node(int v, int h, Node *l, Node *r)原创 2016-06-27 10:47:39 · 220 阅读 · 0 评论 -
1043. Is It a Binary Search Tree
题解参考 :http://blog.csdn.net/acm_ted/article/details/20715415题解:1:通过输入构造二叉排序树2:先序遍历并与输入顺序比较3:如果比较不符合再构造镜像二叉排序树4:比较输出结果#include #include #include #include using namespace std;原创 2016-06-26 17:40:58 · 295 阅读 · 0 评论 -
1098. Insertion or Heap Sort
堆排序都快不会写了。。。加油啊。。。#include #include #include using namespace std;void adjust(int *num, int x, int endd){ int bigger = x; if(2*x + 1 > endd) return; bigger = 2*x + 1; if原创 2016-06-09 17:11:39 · 195 阅读 · 0 评论 -
1007. Maximum Subsequence Sum
注意特殊情况:-1 0 0 -1#include #include #include using namespace std;int main(){ int n; int x; int first = 0; int last = 0; int tempfirst = 0; int maxsum = 0; int sum = 0原创 2016-06-09 15:57:13 · 187 阅读 · 0 评论 -
1067. Sort with Swap(0,*)
注意,易超时。以下是参考别人代码,改进后的代码。#include #include #include using namespace std;int n;int *position;int findchange(int start){ for(int i = start; i < n; i++) { if(position[i] != i)原创 2016-06-09 11:02:21 · 249 阅读 · 0 评论 -
1086. Tree Traversals Again
入栈的顺序是先序访问顺序,出栈的顺序是中序访问顺序#include #include #include #include using namespace std;int n;bool first = true;int *preorder;int *inorder;struct Info{ int value; Info *left; Info *r原创 2016-06-25 10:42:18 · 191 阅读 · 0 评论 -
1020. Tree Traversals
一直不敢写树的题,这道一次过,其实写的时候仔细点就行,和人工的思路一样#include #include #include using namespace std;int n;int *postorder;int *inorder;struct Info{ int value; Info *left; Info *right;};int find原创 2016-06-23 17:01:27 · 220 阅读 · 0 评论