
PAT甲
notmenotme
这个作者很懒,什么都没留下…
展开
-
1013 Battle Over Cities (25 分)图的遍历,dfs,强连通分量个数
dfs(){ dfs() }fill(vis,vis+n+1,0);每次,并且到n+1ct个分量只需要ct-1条路连通#include<iostream>#include<cstdio>using namespace std;int n,m,k,e[1005][1005];int a,b;bool vis[1005];void df...原创 2019-02-27 16:05:41 · 176 阅读 · 0 评论 -
1012 The Best Rank (25 分)排序,cmp
1012 The Best Rank (25 分)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Li...原创 2019-02-27 11:39:26 · 1517 阅读 · 0 评论 -
1072 Gas Station 图的遍历dijkstra
1072 Gas Station (30 分)A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must gu...原创 2019-02-26 20:53:36 · 175 阅读 · 0 评论 -
1003 Emergency (25 分)最短路径dijkstra
1003 Emergency (25 分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams ...原创 2019-02-26 17:17:37 · 249 阅读 · 0 评论 -
1074 Reversing Linked List (25 分)反转链表,标准链表还是用Node好
1074 Reversing Linked List (25 分)Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then yo...原创 2019-02-28 16:38:45 · 128 阅读 · 0 评论 -
1032 Sharing (25 分)链表
1032 Sharing (25 分)To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same ...原创 2019-02-28 15:57:52 · 135 阅读 · 0 评论 -
1114 Family Property (25 分)并查集模板
1114 Family Property (25 分)This time, you are supposed to help us collect the data for family-owned property. Given each person’s family members, and the estate(房产)info under his/her own name, we nee...原创 2019-02-28 14:48:35 · 139 阅读 · 0 评论 -
1153
二维map队列和优先队列friend bool operator < (type a,type b) return ***;原创 2019-02-24 16:03:55 · 448 阅读 · 0 评论 -
1004 Counting Leaves (30 分)树的遍历,dfs,或bfs(层序遍历),vector
1004 Counting Leaves (30 分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one t...原创 2019-02-27 21:12:45 · 180 阅读 · 0 评论 -
快速判单个素数
标准版:大部分人都知道的比较快的方法:判断从2到sqrt(n)是否存在其约数,时间复杂度O(sqrt(n))高配版:判断2之后,就可以判断从3到sqrt(n)之间的奇数了,无需再判断之间的偶数,时间复杂度O(sqrt(n)/2)尊享版:首先看一个关于质数分布的规律:大于等于5的质数一定和6的倍数相邻。例如5和7,11和13,17和19等等;证明:令x≥1,将大于等于5的自然数表示如下:·...转载 2019-02-23 14:41:11 · 292 阅读 · 0 评论 -
1152 Google Recruitment (20 分)前导0,快速判单个素数
- 前导0, 0023不能23 - 素数更快判断,利用素数&gt;3后总在6左右,如5,7 - 低级错误,pow(10,k-1)不是k-1。。1152 Google Recruitment (20 分)In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (sho...原创 2019-02-23 14:29:42 · 182 阅读 · 0 评论 -
1020 Tree Traversals (25 分)树的遍历,后序中序层序,bfs
1020 Tree Traversals (25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order t...原创 2019-02-27 19:55:24 · 129 阅读 · 0 评论 -
1098 Insertion or Heap Sort (25 分)直接插入排序 堆排序
直接插入排序for(int i=1;i&lt;=n;i++) sort(a,a+i);原创 2019-02-27 13:41:52 · 200 阅读 · 0 评论