- 博客(47)
- 收藏
- 关注
原创 PAT-2019年春季考试-甲级7-3 Telefraud Detection (25分)
7-3 Telefraud Detection (25分)Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are su...
2020-03-11 18:11:09
285
3
原创 PAT-2019年冬季考试-甲级7-4 Cartesian Tree (30分)
A Cartesian tree is a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8...
2020-02-21 22:23:11
283
原创 [PAT甲] 2019年冬季考试7-1 Good in C (20分)
这个题目有点搞人Input Specification:Each input file contains one test case. For each case, the first part gives the 26 capital English letters A-Z, each in a 7×5 matrix of C’s and .'s. Then a sentence is gi...
2020-02-21 22:18:54
259
原创 PAT(甲级)2019年秋季考试 7-4 Dijkstra Sequence (30分)
7-4 Dijkstra Sequence (30分)状态:ACedDijkstra’s algorithm is one of the very famous greedy algorithms. It is used for solving the single source shortest path problem which gives the shortest paths from...
2019-12-05 19:26:08
673
原创 PAT(甲级) 2019秋季考试 7-3 Postifix Expression (25分)
7-3 Postfix Expression (25分)状态:ACedGiven a syntax tree (binary), you are supposed to output the corresponding postfix expression, with parentheses reflecting the precedences of the operators.Input ...
2019-12-05 19:19:27
210
原创 PAT(甲级)2019年秋季考试 7-2 Merging Linked Lists (25分)
7-2 Merging Linked Lists (25分)状态:ACedGiven two singly linked lists L1=a1→a2 →⋯→an−1→an and L2=b1→b2→⋯→bm−1→bm . If n≥2m, you are supposed to reverse and merge the shorter one into the longer ...
2019-12-05 19:00:18
847
原创 PAT(甲级)2019年秋季考试 7-1 Forever (20分)
7-1 Forever (20分)“Forever number” is a positive integer A with K digits, satisfying the following constrains:the sum of all the digits of A is m;the sum of all the digits of A+1 is n; andthe great...
2019-12-05 18:52:08
406
原创 FSM(有限状态机)
有限状态机的实现#include <stdio.h>#include <ctype.h>#include <string.h>#define START 0#define STOP 2#define BUILD_ID 3#define BUILD_NUM 4#define IDENTIFER 5#define NUMBER 6#define...
2018-05-24 10:29:28
540
原创 [LeetCode - tree] 662. Maximum Width of Binary Tree
662. Maximum Width of Binary TreeGiven a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the sam
2017-12-02 14:26:16
211
转载 [LeetCode - tree]687. Longest Univalue Path
687. Longest Univalue PathGiven a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.Note: The length of pat
2017-12-02 11:52:51
240
原创 Graph Practise
这里记录一下最近写的关于图的东西,图还是比较难的,这里有些可能不能用,但分开来都是对的#pragma once//带权//此文件不能直接使用#define MAXV 100#define INF 0x3fffffff#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <utili
2017-11-10 18:09:10
206
原创 06-图3 六度空间(30 分)
06-图3 六度空间(30 分)“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。\ “六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标
2017-10-28 21:03:13
585
原创 06-图2 Saving James Bond - Easy Version(25 分)
06-图2 Saving James Bond - Easy Version(25 分)This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dea
2017-10-28 20:58:00
318
原创 05-树9 Huffman Codes(30 分)
05-树9 Huffman Codes(30 分)In 1953, David A. Huffman published his paper “A Method for the Construction of Minimum-Redundancy Codes”, and hence printed his name in the history of computer science. As a p
2017-10-28 20:52:41
741
原创 05-树8 File Transfer(25 分)
05-树8 File Transfer(25 分)We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible
2017-10-28 20:33:31
322
原创 04-树6 Complete Binary Search Tree(30 分)
04-树6 Complete Binary Search Tree(30 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes
2017-10-20 08:43:50
296
原创 04-树5 Root of AVL Tree(25 分)
04-树5 Root of AVL Tree(25 分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they dif
2017-10-20 00:25:15
439
原创 04-树4 是否同一棵二叉搜索树(25 分)
04-树4 是否同一棵二叉搜索树(25 分)给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两
2017-10-20 00:19:15
332
原创 03-树3 Tree Traversals Again(25 分)
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack
2017-10-17 17:17:29
297
原创 03-树2 List Leaves(25 分)
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.Input Specification:Each input file contains one test case. For each case, the first line gives a posit
2017-10-17 00:24:25
357
原创 [Crossword Answers UVA - 232 ]
Crossword Answers UVA - 232#include #include //#define LOCALchar s[12][12];int num[12][12];int main(){ int cases = 0;#ifdef LOCAL freopen("test.txt", "r", stdin);#endif in
2017-10-14 13:09:46
267
原创 [Periodic Strings, UVA455 ]
[Periodic Strings, UVA455 ]#include <stdio.h>#include <string.h>char s[85];int main() { int T; //freopen("test.txt", "r", stdin); scanf("%d", &T); while(T--) { int per[80];
2017-10-14 13:00:49
193
原创 [Molar Mass, ACM/ICPC Seoul 2007, UVA1586]
Molar Mass, ACM/ICPC Seoul 2007, UVA1586
2017-10-13 00:39:02
387
原创 [Score, ACM/ICPC Seoul 2005, UVA1585]
吐槽!!!我好心让最后一行不\n,结果直接wrong answer,全部换行结果AC…#include <stdio.h>char s[85];void showScore(char *s) { int sum = 0; //int tagOfx = 1; int numOfo = 0; for(int i=0; s[i]!='\0'; ++i) {
2017-10-13 00:32:54
256
原创 [Digit Generator, ACM/ICPC Seoul 2005, UVA1583]
大阻力是开10万数组的魄力…#include <stdio.h>#include <string.h>int a[100005];int main(){ memset(a, 0, sizeof(a)); for(int i=1; i<100005; ++i) { int tmp1 = i; int tmp2 = i; while
2017-10-13 00:28:40
250
原创 树的同构(25 分)[有点难度的递归]
树的同构给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。图一图二现给定两棵树,请你判断它们是否是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N (≤10),即该树的结点数(此时假设结点从0
2017-10-12 10:22:08
1982
原创 [UVA - 340] Master-Mind Hints
MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the
2017-10-10 23:56:29
224
原创 [PAT乙] 1019. 数字黑洞 (20)
1019. 数字黑洞 (20)给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的6174,这个神奇的数字也叫Kaprekar常数。例如,我们从6767开始,将得到7766 - 6677 = 1089 9810 - 0189 = 9621 9621 - 12
2017-10-08 23:20:54
274
原创 [PAT] 1015. 德才论 (25)
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录
2017-10-02 14:55:11
190
原创 [PAT乙] 1014. 福尔摩斯的约会 (20)
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母’D’,代表星期四;第2对相同的字符是’E’,那是第5个英文字母,代表一天里的第14个钟头(
2017-10-02 14:26:38
273
原创 [PAT甲] 1051.Pop Sequence
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the
2017-09-30 17:23:42
471
1
原创 [PAT甲] 1074.Reversing Linked List
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 you must output 3→2→1→6→5→4; if K=4,
2017-09-30 17:05:47
193
原创 [PAT乙] 1007. 素数对猜想 (20)
1007. 素数对猜想 (20)让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数。显然有 d1=1 且对于n>1有 dn 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。现给定任意正整数N (< 105),请计算不超过N的满足猜想的素数对的个数。输入格式:每个测试输入包含1个测试用例,给出正整数N。输出格式:每个测试用例的输出占一行,不超过N的满足猜想的素数
2017-09-29 00:55:51
187
原创 [PAT乙] 1005. 继续(3n+1)猜想 (25)
1005. 继续(3n+1)猜想 (25)卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对n=3进行验证的时候,我们需要计算3、5、8、4、2、1,则当我们对n=5、8、4、2进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这4个数已经在验证3的时候遇
2017-09-28 21:41:42
200
原创 [PAT乙] 1003 我要通过!
1003. 我要通过!(20)“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。得到“答案正确”的条件是:字符串中必须仅有P, A, T这三种字符,不可以包含其它字符;任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串
2017-09-28 16:23:04
225
原创 [PTA] 线性结构2 一元多项式的乘法与加法运算(20 分)
线性结构2 一元多项式的乘法与加法运算(20 分)设计函数分别求两个一元多项式的乘积与和。输入格式: 输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式: 输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。零多项式应输出0 0。
2017-09-27 16:01:08
269
原创 [PTA] 线性结构1 两个有序链表序列的合并(15 分)
线性结构1 两个有序链表序列的合并(15 分)本题要求实现一个函数,将两个链表表示的递增整数序列合并为一个非递减的整数序列。函数接口定义: List Merge( List L1, List L2 );其中List结构定义如下:typedef struct Node *PtrToNode;struct Node { ElementType Data; /* 存储结点数据 */ P
2017-09-27 00:24:33
610
原创 [PTA MOOC] 自测-4 Have Fun with Numbers(20 分)
自测-4 Have Fun with Numbers(20 分)
2017-09-02 20:45:27
1161
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人