2019年2月28日

1020 Tree Traversals + L2-011 玩转二叉树 [二叉树遍历]

摘要: 题目大意就是根据树的后序遍历和中序遍历推出层序遍历。 很久没做过这种题了,正好借此复习一下数据结构。 首先是遍历的几个简单介绍。 前序遍历(preorder):根结点->左子树->右子树。 中序遍历(inorder):左子树->根结点->右子树。 后序遍历(postorder):左子树->右子树-> 阅读全文

posted @ 2019-02-28 21:11 FTA_Macro 阅读(195) 评论(0) 推荐(0) 编辑

1013 Battle Over Cities [并查集]

摘要: 题目大意就是给出几个城市相连的图,把其中某个城市连同它与其他城市的的路径一起去掉,问最少需要加几条路让剩余的城市都相连。 这应该是并查集的基础题了,把其中一个点去掉,看一下剩下几个集合减一就得到最少结果了。注意一下路径数组的范围。详见代码。 #include <iostream> #include 阅读全文

posted @ 2019-02-28 19:25 FTA_Macro 阅读(104) 评论(0) 推荐(0) 编辑

1054 The Dominant Color

摘要: 题目大意就是找到一些数中出现最多次数的数。 一开始把数的范围看成了242,用string和cin写了一遍,其中一个超时。。。 正准备改成scanf,发现是224,20分的题花了半个小时,被自己菜哭 用map存出现次数,再记录最大次数,用一个数组记录出现的数,找一遍即可。水题~ #include <i 阅读全文

posted @ 2019-02-28 16:48 FTA_Macro 阅读(122) 评论(0) 推荐(0) 编辑

1050 String Subtraction

摘要: 题目意思就是给两个字符串母串和子串,用母串减去子串,得到一个不包含子串中字符的母串。 用map和getline即可,水题~ #include <iostream> #include <string.h> #include <stdio.h> #include <string> #include <m 阅读全文

posted @ 2019-02-28 15:44 FTA_Macro 阅读(150) 评论(0) 推荐(0) 编辑

1046 Shortest Distance

摘要: 题目大意是给你一个环上相邻两点之间的距离,问你任意两点间的最短距离。 用前缀和,判断顺着和逆着走哪边小,注意查询点的位置不一定是后面比前面大。水题~ #include <iostream> #include <string.h> using namespace std; #define maxn 1 阅读全文

posted @ 2019-02-28 15:28 FTA_Macro 阅读(133) 评论(0) 推荐(0) 编辑

2019年2月6日

1041 Be Unique

摘要: 题目意思就是找到第一个没有重复的数,数据只有10^5,所以用数组水了一下。如果比较大的话应该要用map和vector。 #include <iostream> #include <string.h> #define maxn 100005 int a[maxn],b[maxn]; int main( 阅读全文

posted @ 2019-02-06 11:43 FTA_Macro 阅读(235) 评论(0) 推荐(0) 编辑

2019年1月22日

1120 Friend Numbers

摘要: 题目大意是求一些数字的各位和,看一下有多少不同的,并且按升序输出,水题~ #include <iostream> #include <cstring> #include <string> #include <sstream> #include <string> #include <cstdio> # 阅读全文

posted @ 2019-01-22 20:26 FTA_Macro 阅读(192) 评论(0) 推荐(0) 编辑

1144 The Missing Number

摘要: 题目大意是找出没有在给定数列中最小的正数。 20分,水题,一开始写了个map暴力,果然可以过_(:3」∠)_ 想了想,把所有正数排序去重一下,最差的情况就是从1到n都已经有了,详见代码。 #include <iostream> #include <cstring> #include <string> 阅读全文

posted @ 2019-01-22 13:48 FTA_Macro 阅读(118) 评论(0) 推荐(0) 编辑

2019年1月21日

1019 General Palindromic Number

摘要: 题目大意是让你把一个数转化为给定的进制数,然后判断该进制数是否是回文串。水题~ #include <iostream> #include <cstring> #include <string> #include <sstream> #include <string> #include <cstdio 阅读全文

posted @ 2019-01-21 22:41 FTA_Macro 阅读(148) 评论(0) 推荐(0) 编辑

1152 Google Recruitment

摘要: 题目大意不难懂,在一串字符中找到第一个K位素数。 20分的题,暴力就能做。有两个小点,一个是字符串string转成数字有一个stoi函数,还有一个就是截取string字符串中某一段连续的子串可以简洁写为string ts(s,i,l),其中s是母串,i是起始位置,j是要截取的长度。 判断素数用O(√ 阅读全文

posted @ 2019-01-21 18:58 FTA_Macro 阅读(242) 评论(0) 推荐(0) 编辑

导航