自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(249)
  • 收藏
  • 关注

原创 Unity 2021 到底能不能用 foreach ?

Unity Profiler 的结果如下,可以看到只有在 foreach 中使用 ArrayList 会引起 GC。开启 Deep Profile ,进一步确定 GC 是由。测试的 Unity 版本为 2021。,但是不会 Alloc ,

2022-10-18 14:02:25 994 1

原创 PAT A1005 Spell It Right (20 分)

1005 Spell It Right (20 分)Given a non-negative integer NNN, your task is to compute the sum of all the digits of NNN, and output every digit of the sum in English.Input SpecificationEach input file contains one test case. Each case occupies one line whi

2022-04-16 22:39:24 401

原创 PAT A1004 Counting Leaves (30 分)

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 test case. Each case starts with a line containing 0<N

2022-04-16 22:36:57 730

原创 PAT A1003 Emergency (25 分)

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 in each city and the length of each road between any pai

2022-04-16 22:34:13 98

原创 PAT A1002 A+B for Polynomials (25 分)

1002 A+B for Polynomials (25 分)This time, you are supposed to find A+BA+BA+B where AAA and BBB are two polynomials.Input SpecificationEach input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynom

2022-04-16 22:30:16 95

原创 PAT A1001 A+B Format (20 分)

1001 A+B Format (20 分)Calculate a+ba+ba+b and 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 SpecificationEach input file contains one test case. Ea

2022-04-16 22:28:02 260

原创 为什么最好不要定义虚拷贝赋值

从语用的角度,拷贝操作和移动操作都是为了具体类型而设计的,而不是有继承层级的抽象类型.完整的拷贝操作需要两个函数,但是因为构造函数不能是虚,只能定义虚的拷贝赋值函数,这样就破坏了拷贝操作的完整性.如果要定义成虚的,下面这种解决方案应该是最好的,但是由于 1 中所说的原因,还不如删掉拷贝操作,然后定义一个虚的 clone 函数,这样更加清晰,这也是本杰明建议的做法.class B{public: // _copy() not required for base class virtual.

2022-04-16 12:34:46 290

原创 PAT(甲级)2022 年春季 7-4

这次题好难……我 100 的时候一共才 4 个还是 5 个人。// map 是 n * m 的// x 是救助点// # 不能走// 一条指令是一个数字// 0123 代表 北东南西// 如果目的地不能到达,必须等待下一条指令// 一种贪心算法// 1. 找到 x 的单源最短路径,然后选一个最远的 A ,这个 A 是人可能在的位置// 2. 生成从 A 到 x 的最短路径,如果最短路不唯一,就生成最小的// 3. 计算人目前可能的位置// 4. 如果 x 是人唯一可能在的位置,停止,

2022-03-05 16:42:07 611 6

原创 PAT(甲级)2022 年春季 7-3

// 二叉搜索树// 左子树小于// 右子树大于等于#include <bits/stdc++.h>using namespace std;void in_trav(vector<int> &tree, vector<int> &in_order, int id) { int size = tree.size(); if (id * 2 < size and tree[id * 2] != -1) {

2022-03-05 16:40:19 245

原创 PAT(甲级)2022 年春季 7-2

// 找出前 K 个最大的数,并按照降序输出#include <bits/stdc++.h>using namespace std;int main() {#ifdef YD_DEBUG freopen("../in", "r", stdin); freopen("../out", "w", stdout);#endif cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false)

2022-03-05 16:39:37 305

原创 PAT(甲级)2022 年春季 7-1

// N 个多选题, 8 个选项 a-h// 获得一个长度为 N 的 string// 得分超过 T 的是// f 开头 -2// a 结尾 -1// 每个最长的相同字母的串的长度大于 5 ,+3// a 后面是 e 或 h -4// 每个最长的连续增长的串的长度大于 3 ,+5// N 问题的个数// T 阈值// K 测试者#include <bits/stdc++.h>using namespace std;int main() {#ifdef YD_

2022-03-05 16:38:17 200

原创 PAT 甲级考试终于满分了

竟然有两份证书。申通快递把证书撕坏了好气啊。先留个坑,这应该是个经验贴,等我有时间/心情的时候再说吧。

2021-03-20 18:09:59 1567 3

转载 Mac 升级 Git 版本

不吹牛的说,这篇文章绝对是目前网上最简单的 Git 升级教程了安装 HomebrewHomebrew 是一个软件包管理器。它的作用就是将软件包安装到自己的目录中,然后将其文件符号链接到 /usr/local。更多信息,请自行进入官网查看。在将下面代码复制进终端,点击回车,然后打开零食,边吃边等就好。/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"升级

2021-03-15 12:43:14 684

原创 7-4 Professional Ability Test (30 分)

#include <algorithm>#include <iostream>#include <queue>#include <unordered_set>#include <vector>using namespace std;struct Node { int T, S; Node() {} Node(int T, int S) : T(T), S(S) {}};bool is_consisten

2021-03-15 10:46:02 695

原创 7-3 Left-View of Binary Tree (25 分)

#include <iostream>#include <queue>#include <vector>using namespace std;struct Node { int val, level; Node *left, *right;};Node *rebuild(vector<int> &in, vector<int> &pre, int inL, int preL, int len, i

2021-03-15 10:45:09 125

原创 7-2 How Many Ways to Buy a Piece of Land (25 分)

#include <iostream>#include <vector>using namespace std;int main() { int N, M; cin >> N >> M; vector<int> prices(N); for (int i = 0; i < N; i++) { cin >> prices[i]; } int ways =

2021-03-15 10:44:22 109

原创 7-1 Panda and PP Milk (20分)

#include <iostream>using namespace std;int w[10005], m[10005];int main() { int n; cin >> n; m[0] = 200; cin >> w[0]; for (int i = 1; i < n; ++i) { cin >> w[i]; // 体重相等 if (w[i]

2021-03-15 10:43:09 90

原创 7-4 Chemical Equation (30 分)

#include <algorithm>#include <iostream>#include <map>#include <queue>#include <string>#include <unordered_set>#include <vector>using namespace std;unordered_set<string> reactants;vector<string&g

2021-03-14 14:08:00 323

原创 7-3 File Path (25 分)

#include <iostream>#include <string>#include <vector>using namespace std;struct Node { string name; vector<Node*> children; Node* parent;};bool dfs(string& id, Node* file, vector<string>& path) { if (file-

2021-03-14 14:07:21 114

原创 7-2 Subsequence in Substring (25 分)

#include <iostream>using namespace std;int main() { string str1, str2; cin >> str1 >> str2; int start = 0, len = str1.length(); for (int i = 0; i < str1.length(); i++) { if (str1[i] == str2[0]) {

2021-03-14 14:06:47 152

原创 7-1 The Closest Fibonacci Number (20 分)

#include <iostream>#include <algorithm>#include <vector>using namespace std;vector<int> gen_fb() { vector<int> fb = {0, 1}; for (int i = 2; fb.back() < 1e8; i++) { fb.push_back(fb[i - 1] + fb[i - 2]);

2021-03-14 14:06:12 112

原创 7-4 Recycling of Shared Bicycles (30 分)

#include <iostream>#include <queue>#include <vector>#include <algorithm>using namespace std;struct Node { int v, d; Node() {} Node(int v, int d) :v(v), d(d) {}};vector<vector<Node>> adj;void dijkstra(int s

2021-03-13 17:32:35 587 5

原创 7-3 Structure of Max-Heap (25 分)

#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <string>using namespace std;int last = 0;int heap[1005];void insert(int val) { int p = ++last; heap[p] = val; for (; p / 2 >= 1; p /= 2) { if (heap[p] > heap[p / 2]

2021-03-13 17:31:56 394

原创 7-2 Lab Access Scheduling (25 分)

#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <algorithm>#include <vector>using namespace std;int timestamp(int h, int m, int s) { return s + m * 60 + h * 3600;}int main(){ int n; cin >> n; if (n == 0)

2021-03-13 17:31:26 260

原创 7-1 Arithmetic Progression of Primes (20 分)

#include <iostream>#include <algorithm>using namespace std;bool is_prime[100005];int MAXP, n;int main(){ cin >> n >> MAXP; fill(is_prime + 2, is_prime + 1 + MAXP, true); for (int i = 2; i <= MAXP; i++) { for (int j

2021-03-13 17:30:47 563 1

原创 PAT (Advanced Level) Practice 1106 Lowest Price in Supply Chain (25 分)

题目详情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 the chain buys products from one’s supplier in a price

2021-02-25 12:06:05 101

原创 PAT (Advanced Level) Practice 1105 Spiral Matrix (25 分)

题目详情This time your job is to fill a sequence of NNN positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The matrix has mmm rows and

2021-02-25 12:05:17 80

原创 PAT (Advanced Level) Practice 1104 Sum of Number Segments (20 分)

题目详情Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3,

2021-02-25 12:04:21 89

原创 PAT (Advanced Level) Practice 1103 Integer Factorization (30 分)

题目详情The K−PK-PK−P factorization of a positive integer NNN is to write NNN as the sum of the PPP-th power of KKK positive integers. You are supposed to write a program to find the K−PK-PK−P factorization of NNN for any positive integers NNN, KKK and PPP.I

2021-02-25 12:03:23 74

原创 PAT (Advanced Level) Practice 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 turn to prove that YOU CAN invert a binary tree!Input Specif

2021-02-25 12:02:22 82

原创 PAT (Advanced Level) Practice 1101 Quick Sort (25 分)

题目详情There is a classical process named partition in 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 left and those larger than the pivot to its right. Gi

2021-02-23 20:35:00 75

原创 PAT (Advanced Level) Practice 1100 Mars Numbers (20 分)

题目详情People on Mars count their numbers with base 13:Zero on Earth is called “tret” on Mars.The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively.For the next higher digit, Mars people

2021-02-23 19:58:01 110

原创 LeetCode 23 Merge k Sorted Lists

LeetCode 23 Merge k Sorted ListsDescriptionMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解题思路可以把第21题两路归并的代码拿过来用。代码class Solution {p...

2021-02-21 12:31:02 98

原创 LeetCode 32 Longest Valid Parentheses (栈,括号匹配)

LeetCode 32 Longest Valid Parentheses (栈,括号匹配)DescriptionGiven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For...

2021-02-21 12:30:48 115

原创 BUAA OJ 871 The stupid owls

BUAA OJ 871 The stupid owls题目描述Bamboo recently bought an owl for sending and receiving letters. Every owl will bring a letter to exactly one person, so normally Bamboo’s owl will only bring letter...

2021-02-21 12:30:35 159

原创 BUAA OJ 858 群鸦的盛宴

BUAA OJ 858 群鸦的盛宴题目描述AlvinZH总是比别人慢一拍,比如暑假大家都在追权游7讨论龙母和雪诺大人尴尬相遇的时候,他还在第一季震惊地看着三只刚出生的小龙。AlvinZH的进度很慢,因为他一边刷着电视剧,一边还在看原版小说,所以现在才看到第五季,雪诺在这头,龙母在那头。AlvinZH发现书中各城堡之间的通信工具都是乌鸦,经过训练的乌鸦能够及时传递消息,使得主角总能绝...

2021-02-21 12:30:25 148

原创 LeetCode 799 Champagne Tower

LeetCode 799 Champagne TowerDescriptionWe stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup (250ml...

2021-02-21 12:30:10 212 2

原创 树的遍历 ALDS1_7_C: Tree Walk

递归版#include &lt;cstdio&gt;#define MAX 10000#define NIL -1using namespace std;struct node{ int parent; int left; int right;};node binaryTree[MAX];int n;//前序遍历void preParse(...

2021-02-21 12:29:09 219

原创 重构二叉树

node* makeTree(int* in, int* post, int len){ if(len){ int root=0; for(;root&lt;len;root++) if(in[root]==post[len-1]) break; node* p=new node(pos...

2021-02-21 12:28:26 171

原创 if __name__ == ‘__main__‘

__name__:类或模块的名字。 __main__:主模块的名字。原文出处 两个文件:# file one.pydef func(): print("func() in one.py")print("top-level in one.py")if __name__ == "__main__": print("one.py is being run directly")eli

2021-02-21 12:26:43 166

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除