
c++
文章平均质量分 53
DedicateToAI
这个作者很懒,什么都没留下…
展开
-
阿里3.25笔试题
自己写的bullshit,第一题5%,第二题0%第一题原来写的代码:思路是首先对矩阵所有数求和,然后取平均值,接下来,找到每一列最接近平均值的数,使得起伏最小。只通过了5%。#include <iostream>#include <cstdio>#include<vector>#include<algorithm>usi...原创 2020-04-09 23:01:18 · 731 阅读 · 0 评论 -
2019.12.7PAT冬季考试第四题 - 7-4 Cartesian Tree (30分)
ACartesian treeis 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-01-01 22:58:06 · 348 阅读 · 0 评论 -
2019.12.7PAT冬季考试第二题 - 7-3 Summit (25分)
7-3Summit(25分)Asummit(峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so...原创 2020-01-01 22:37:51 · 546 阅读 · 0 评论 -
2019.12.7PAT冬季考试第二题 - 7-2 Block Reversing (25分)
Given a singly linked listL. Let us consider everyKnodes as ablock(if there are less thanKnodes at the end of the list, the rest of the nodes are still considered as a block). Your job is to re...原创 2020-01-01 22:16:58 · 309 阅读 · 0 评论 -
2019.12.7PAT冬季考试第一题 - 7-1 Good in C (20分)
第一题7-1Good in C(20分)When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?Input Specification:Each input file contains one test case. For ...原创 2020-01-01 22:01:19 · 327 阅读 · 0 评论 -
总结与反思 - 12月7日冬季PAT甲级考试
第一次参加PAT甲级考试,地点在上海大学计算中心。首先要说下这个位置,地图上没有明显的标识,准考证上也没有明确的写,最后是靠自己问路问来的。上海大学计算中心:首先找到图书馆附近,然后找D楼,D楼的4楼就是计算中心啦。然后说下环境,机房是比较老的了,不过看上去编译环境还是比较齐全的,python, java, c都有,因为自己之前一直是用的VS2019,这次也打开了vs2010,然后就被坑...原创 2019-12-12 11:25:04 · 325 阅读 · 0 评论 -
PAT甲级简单题最后冲刺
A1001Calculatea+band output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Eac...原创 2019-12-07 00:03:16 · 455 阅读 · 0 评论 -
PAT甲级 - 1018 Public Bike Management (30分)
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the...原创 2019-12-06 19:24:22 · 214 阅读 · 0 评论 -
PAT甲级 - 1021 Deepest Root (25分)
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root...原创 2019-12-05 20:19:54 · 174 阅读 · 0 评论 -
PAT甲级 -1013 Battle Over Cities (25分) 求连通块的数量
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we ne...原创 2019-12-04 21:26:54 · 210 阅读 · 0 评论 -
PAT甲级 - 1098 Insertion or Heap Sort (25 分) 堆排序,找规律
According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data...原创 2019-12-04 11:25:04 · 250 阅读 · 0 评论 -
PAT甲级 - 1107 Social Clusters (30 分) 并查集
When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. Asocial clusteris a set of people who have some of the...原创 2019-12-02 21:58:30 · 195 阅读 · 0 评论 -
PAT甲级1066 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 differ by more than one, rebalancing i...原创 2019-12-02 18:12:43 · 190 阅读 · 0 评论 -
PAT甲级 - 1099 Build A 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 with keys less than the node's key. The right s...原创 2019-12-01 22:08:46 · 183 阅读 · 0 评论 -
PAT - 1064 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 with keys less than the node's key. The right s...原创 2019-12-01 21:32:08 · 195 阅读 · 0 评论 -
PAT甲级 - 1094 The Largest Generation (25 分) 树+DFS
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.Input...原创 2019-12-01 18:50:36 · 165 阅读 · 0 评论 -
PAT甲级 - 1090 Highest Price in Supply Chain (25 分) 树+DFS
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on t...原创 2019-12-01 18:12:56 · 200 阅读 · 0 评论 -
PAT甲级 - 1079 Total Sales of Supply Chain (25 分) 树+BFS
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on t...原创 2019-11-30 21:51:08 · 252 阅读 · 0 评论 -
PAT甲级 - 1102 Invert a Binary Tree (25 分) 反转二叉树
The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off.Now it's your tur...原创 2019-11-30 19:40:32 · 233 阅读 · 1 评论 -
PAT甲级- 1086 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 sta...原创 2019-11-30 18:09:44 · 185 阅读 · 0 评论 -
PAT甲级1105 Spiral Matrix (25 分) 模拟
This time your job is to fill a sequence ofNpositive integers into aspiral matrixin non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then mov...原创 2019-11-29 21:48:27 · 176 阅读 · 0 评论 -
PAT甲级 - 1057 Stack (30 分) 分块思想
Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and P...原创 2019-11-28 23:16:36 · 275 阅读 · 0 评论 -
PAT甲级 - 1068 Find More Coins (30 分) DFS 和DP
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However...原创 2019-11-28 20:42:09 · 208 阅读 · 0 评论 -
PAT甲级- 1040 Longest Symmetric String (25 分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, givenIs PAT&TAP symmetric?, the longest symmetric sub-string iss PAT&TAP s, hence you...原创 2019-11-27 21:49:49 · 198 阅读 · 0 评论 -
PAT甲级 -1045 Favorite Color Stripe (30 分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining p...原创 2019-11-27 20:30:00 · 237 阅读 · 0 评论 -
PAT甲级 1007 Maximum Subsequence Sum (25 分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subse...原创 2019-11-24 22:44:39 · 149 阅读 · 0 评论 -
字符串Hash
给出N个只有小写字母的字符串,求其中的不同的字符串的个数#include<iostream>#include<string>#include<algorithm>#include<vector>using namespace std;const int MOD = 1000000007;const int P = 1000001...原创 2019-11-22 23:28:40 · 136 阅读 · 0 评论 -
PAT甲级 - 1030 Travel Plan (30 分)
A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path ...原创 2019-11-17 12:42:03 · 159 阅读 · 0 评论 -
PAT甲级 - 1003 Emergency (25 分) Dijstra和BF算法
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 in each city and the ...原创 2019-11-15 12:35:45 · 246 阅读 · 0 评论 -
PAT - 1076 Forwards on Weibo (30 分) 图的BFS遍历
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a...原创 2019-11-13 23:14:25 · 182 阅读 · 0 评论 -
PAT - 1034 Head of a Gang (30 分) 图的DFS
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be ...原创 2019-11-13 16:16:47 · 171 阅读 · 0 评论 -
PAT - A1043 Is It a Binary Search Tree (25 分)
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 with keys less than the node's key. The right s...原创 2019-11-09 13:02:51 · 197 阅读 · 0 评论 -
PAT - 1020 Tree Traversals
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 traversal sequence of the co...原创 2019-11-08 10:49:29 · 135 阅读 · 0 评论 -
PAT - BFS
例题1,给出一个m*n的矩阵,矩阵中的元素为0或1,称位置x与其上下左右四个位置是相邻的。若有若干个1相邻,成这些1构成了一个块。例如如下的矩阵中输入样例: 6 7 0 1 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 1 1 0 0 0...原创 2019-11-05 16:21:45 · 192 阅读 · 0 评论 -
PAT - DFS
使用DFS可以解决枚举子序列问题:给定一个序列,枚举这个序列的所有子序列。因为每个数总有两种状态,选与不选,然后进行递归即可。枚举从N个整数中选择K个数的方案是子问题。例题:从序列A(n个数)中选K个数,使得和为x,且序列的平方和最大。 //有边界,提前判断//序列A中n个数选k个数使得和为x,最大平方和为maxSumSqu#include<cstdio>#incl...原创 2019-11-01 22:28:20 · 189 阅读 · 0 评论 -
PAT - 栈、队列、链表
【Codeup 1918】简单计算器数据结构node,用来存储操作数和操作符,flag来表示类型 stack操作符栈【遇到相等或者高优先级操作符,弹出】;queue用来存储转换成的后缀表达式;map实现操作符优先级的映射。 使用(getline(cin, str), str!= "0"),来输入若干字符串str,str = "0",终止输入。 使用 string::iterator i...原创 2019-10-31 22:05:11 · 319 阅读 · 0 评论 -
1101 Quick Sort (25 分)- PAT甲级真题-多种算法及分析
There is a classical process namedpartitionin the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its l...原创 2019-10-22 13:16:14 · 899 阅读 · 3 评论 -
贪心 - PAT B - 1020 月饼 (25 分)
#include<cstdio>#include<algorithm>using namespace std;struct cake{ double number; double total_price; double per_price;}mooncakes[1010];bool cmp(cake a, cake b){ r...原创 2019-10-18 22:08:25 · 166 阅读 · 0 评论 -
一些比较难懂的递归题目 c++
全排列问题#include<cstdio>const int maxn = 11;int n, P[maxn], hashTable[maxn] = { false };void generateP(int index) { if (index == n + 1) { for (int i = 1; i <= n; i++) { printf("%d"...原创 2019-10-18 15:53:55 · 548 阅读 · 0 评论 -
排序 - PAT甲级 1025 PAT Ranking (25 分) C / C++
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;struct testee { char regis_num[15]; int score; int final_rank; int local_num; int local_rank;}tes...原创 2019-10-17 22:43:01 · 191 阅读 · 0 评论