
PAT
LiuY_ang
这个作者很懒,什么都没留下…
展开
-
Raffle for Weibo Followers
题目描述:https://www.patest.cn/contests/pat-a-practise/1124/**明确题意:是从获奖的那个人开始的第n个人为下一个获奖的人。要不这么理解本题的难度就要加大。*/#include <iostream>#include <string.h>using namespace std;#define MAX 1010#define N 22ty原创 2017-03-07 19:53:58 · 342 阅读 · 0 评论 -
1090. Highest Price in Supply Chain (25)
题目信息: https://www.patest.cn/contests/pat-a-practise/1090提交情况: 提交代码:#include <iostream>#include <string.h>#include <vector>#include <math.h>#define Max 100010using namespace std;vector<int> child原创 2017-04-15 11:42:31 · 287 阅读 · 0 评论 -
1107. Social Clusters (30)
题目详情:https://www.patest.cn/contests/pat-a-practise/1107提交: 提交代码:#include <iostream>#include <vector>#include <algorithm>using namespace std;#define N 1010int hobby[N],likePerson[N];int n,isRoot[翻译 2017-04-19 16:01:02 · 351 阅读 · 0 评论 -
1079. Total Sales of Supply Chain (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1079提交情况:代码:#include <iostream>#include <vector>#include <math.h> using namespace std;#define Max 100010//depths[]存储各节点的深度 //isRoot[]存储各个节点是否为根节原创 2017-04-16 09:54:48 · 368 阅读 · 0 评论 -
1094. The Largest Generation (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1094提交情况: 提交代码:#include <iostream>#include <vector>using namespace std;#define Max 110int n,m,level[Max],maxLevel,visit[Max]; //level[Max]记录各节点的原创 2017-04-16 11:21:51 · 351 阅读 · 0 评论 -
1004. Counting Leaves (30)
题目详情:https://www.patest.cn/contests/pat-a-practise/1004提交情况:#include <iostream>#include <vector>#include <string.h>using namespace std;#define N 110vector<int> child[N];int n,m,Levels[N],maxLevel原创 2017-04-17 10:39:11 · 259 阅读 · 0 评论 -
1106. Lowest Price in Supply Chain (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1106提交情况:提交代码:#include <iostream>#include <string.h>#include <vector>#include <math.h>using namespace std;#define Max 100010#define INF 0x3f3f3f原创 2017-04-16 11:40:01 · 410 阅读 · 0 评论 -
1053. Path of Equal Weight (30)
题目详情:https://www.patest.cn/contests/pat-a-practise/1053提交: 提交代码:#include <iostream>#include <string.h>#include <vector>#include <algorithm>using namespace std;#define N 110#define INF 0x3f3f3f3f原创 2017-04-17 13:36:15 · 360 阅读 · 0 评论 -
1135. Is It A Red-Black Tree (30)
题目详情:https://www.patest.cn/contests/pat-a-practise/1135 刚看到这道题的感觉很难,现在做出来了,感觉也就那么回事啊[傲娇脸]! 红黑树满足以下5条性质: 1、节点是红色或者黑色 2、根节点为黑色 3、每个叶节点(NIL节点,空节点)是黑色的 4、每个红色节点的子节点都是黑色的,即不能有两个连续的红色节点 5、从任一节点到其每个叶子的原创 2017-10-06 20:17:07 · 923 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1007 最大字串和问题,但是我却思考了好久,原因是我没有看清题意[衰]。例子中给出的输出也太具有迷惑性了,当然主要还是看清题意。特此谨记!#include <iostream>using namespace std;#define K 10001int main(){ int k原创 2017-10-08 10:55:02 · 291 阅读 · 0 评论 -
1134. Vertex Cover (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1134 Vertex Cover(边覆盖):在图G=(V,E)中,是否存在顶点的子集,包含G中的每一条边e;如果存在这样的顶点的子集那么就为Vertex Cover,否则就不是。#include <iostream>#include <vector>#include <map>#inclu原创 2017-10-05 23:01:02 · 578 阅读 · 0 评论 -
1133. Splitting A Linked List (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1133这道题关键在与”链表”的访问和输出的空值。我一开始按照链表的输入顺序进行输出导致出错。 我用Pyhon写的,容易导致一些莫名其妙的错误,建议还是用C,C++写吧。用Python写得控制输入输出。但是在Mac上写,C、C++的输入又成问题了,只能在命令行下一遍遍的手动输。另外Pyhon运行较原创 2017-10-05 23:43:17 · 566 阅读 · 0 评论 -
1115. Counting Nodes in a BST (30)
题目详情:https://www.patest.cn/contests/pat-a-practise/1115感觉很简单,但是没有写temp->left=NULL 和 temp->right=NULL 导致程序写错了,想了好长时间!特此纪念!#include <iostream>#include <malloc.h>#include <vector>using namespace std;t原创 2017-10-21 20:03:59 · 300 阅读 · 0 评论 -
1119. Pre- and Post-order Traversals (30)
题目链接:https://www.patest.cn/contests/pat-a-practise/1119以题目给的例子说以下思路: 一、[1, 2, 3, 4, 6, 7, 5] [2, 6, 7, 4, 5, 3, 1] 1、前序遍历的第一个,后序遍历的最后一个节点的元素都为1,这是根节点 2、接下来判断该树是否唯一。 方法: 前序遍历完根节点后,应该会去遍历左子树原创 2017-10-22 11:10:28 · 299 阅读 · 0 评论 -
1101. Quick Sort (25)
题目链接:https://www.patest.cn/contests/pat-a-practise/1101思路:设置两个数组int min_so_far[N],max_so_far[N] 。 假设在位置pos,namemin_so_far[pos] 用来记录从pos到n-1之间的最小值,即位置pos右边的最小值; max_so_far[N] 用来记录从位置0到pos的最大值,即位置左边的最大值原创 2017-10-22 17:08:32 · 344 阅读 · 0 评论 -
1013. Battle Over Cities (25)
#include <iostream>#include <string.h>using namespace std;#define MAX 1010int graph[MAX][MAX]; //邻接矩阵用于存储图 int check[MAX],visit[MAX],key,n,m,k;void DFS( int start );int main (){ int a,b;原创 2017-04-06 14:34:44 · 315 阅读 · 0 评论 -
1102. Invert a Binary Tree (25)
提交情况:代码:#include <iostream>#include <vector>#include <string.h>using namespace std;#define N 11typedef struct Node { int leftChild; int rightChild;}Node;Node node[N];int n,root[N];vec原创 2017-04-15 10:42:18 · 291 阅读 · 0 评论 -
1066. Root of AVL Tree (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1066提交:代码:#include <iostream>#include <malloc.h>using namespace std;#define N 22int n,number[N];typedef struct AVL{ int data,height; //heigh原创 2017-04-19 11:53:23 · 355 阅读 · 0 评论 -
Chain the Ropes
题目描述:https://www.patest.cn/contests/pat-a-practise/1125#include <iostream>#include <algorithm>using namespace std;#define MAX 10010int main (){ int n,i; int j; double num[MAX]; cin原创 2017-03-07 21:19:58 · 601 阅读 · 0 评论 -
1021. Deepest Root (25)
算法思想:用并查集取得连通分量的个数。然后把每个节点都分别作为根节点,求得该节点作为根的树高 ,并保存在数组中。最后输出。 #include <iostream>#include <vector>#include <string.h>#include <algorithm>using namespace std;#define Max 10002vector<int> G[Max];原创 2017-04-07 15:45:21 · 288 阅读 · 0 评论 -
1034. Head of a Gang (30)
#include <iostream>#include <string>#include <map>using namespace std;#define Max 2010 //一开始我把Max定义为1010结果出现了段错误。后来突然想到n条通话记录最多可以有2*n个人进行通话。 //所以需要把Max设置为2000以上 map<string,int>原创 2017-04-08 11:30:04 · 298 阅读 · 0 评论 -
1076. Forwards on Weibo (30)
#include <iostream>#include <vector>#include <string.h> #define Max 1010using namespace std;vector<int> Graph[Max]; //用邻接表存储图 int queue[Max],front,rear; //队列原创 2017-04-08 17:39:30 · 278 阅读 · 0 评论 -
1003. Emergency (25)
提交情况: #include <iostream>#include <string.h>using namespace std;#define Max 510#define INF 0x3f3f3f3f //Graph为邻接矩阵存储图,weight为点权,w记录最短路径上的点权之和 int Graph[Max][Max],weight[Max],w[Max];//visit为访问数组原创 2017-04-09 12:42:29 · 414 阅读 · 0 评论 -
1001. A+B Format (20)
#include <iostream>using namespace std;int main (){ int a,b; int stack[10],top = -1; while(scanf("%d%d",&a,&b)!=EOF) { top = -1; int sum = a+b,count = 0; int原创 2017-04-01 11:34:56 · 474 阅读 · 0 评论 -
1043. Is It a Binary Search Tree (25)
题目详情:https://www.patest.cn/contests/pat-a-practise/1043提交: 提交代码:#include <iostream>#include <malloc.h>#include <vector>using namespace std;#define N 1010typedef struct BTree{ int data; s原创 2017-04-17 21:07:12 · 349 阅读 · 0 评论 -
1018. Public Bike Management (30)
这里写代码片原创 2017-04-13 17:13:41 · 370 阅读 · 0 评论 -
1030. Travel Plan (30)
提交情况:代码:#include <iostream>#include <string.h>using namespace std;#define Max 505#define INF 0x3f3f3f3ftypedef struct Node{ int length; int cost;}Node;Node Graph[Max][Max];int n,m,s,d;原创 2017-04-14 10:02:18 · 350 阅读 · 0 评论 -
1020. Tree Traversals (25)
题目信息:https://www.patest.cn/contests/pat-a-practise/1020提交情况:代码:#include <iostream>#include <malloc.h>#include <vector>using namespace std;#define N 33typedef struct BTree{ int data; struc原创 2017-04-14 11:24:27 · 267 阅读 · 0 评论 -
1064. Complete Binary Search Tree (30)
题目详情:https://www.patest.cn/contests/pat-a-practise/1064提交:代码:#include <iostream>#include <algorithm>using namespace std;#define N 1010int n,number[N],CBT[N],index = -1;void inOrder( int root ){翻译 2017-04-18 15:10:17 · 456 阅读 · 0 评论 -
1099. Build A Binary Search Tree (30)
题目详情: https://www.patest.cn/contests/pat-a-practise/1099提交:提交代码:#include <iostream>#include <algorithm>using namespace std;#define N 110typedef struct Node{ int data; int leftChild; in原创 2017-04-18 16:28:21 · 378 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
提交情况:代码:#include <iostream>#include <string>#include <vector>#include <malloc.h>using namespace std;#define N 33#define INF 0x3f3f3f3fint number[N],top = -1,count,n;vector<int> num;typedef str原创 2017-04-14 15:41:55 · 376 阅读 · 0 评论 -
1098. Insertion or Heap Sort (25)
只有部分正确,苦思凝想也没弄清楚剩下的那两分是什么地方没有考虑到,欢迎各位大神指点! #include <iostream>using namespace std;#define N 110int num[N],pSorted[N],n,hnum[N];bool isSame(int a[],int b[]){ for(int i=1;i<=n;++i) {原创 2017-04-04 11:53:57 · 430 阅读 · 0 评论 -
1118. Birds in Forest (25)
题目链接:https://www.patest.cn/contests/pat-a-practise/1118根据这道题,发现自己对并查集的理解有误,根据自己的理解写出来的代码只得了17分,剩下的8分没有想出来到底那里错了。然后……然后就上网搜了答案![衰]!明明知道用什么方法,却写不出来,真弱啊!#include <iostream>using namespace std;#define N原创 2017-10-26 23:05:44 · 310 阅读 · 0 评论