Mac terminal终端或iterm2【 ?~?】~两边出现问号、字体有背景色的问题

主要是mac下oh-my-zsh配置主题的时候字体出了问题

关于字体有背景色问题,打开terminal的偏好设置,点击描述文件(profiles),把“显示ANSI颜色”选项取消即可

关于波浪线两边的两个问号问题,是因为配置中有非ascii字符编码,这两个问号本来是好看的箭头,但是箭头在当前字体中是不会被显示的……所以解决方法是重新下载一个支持非ascii编码的字体:

github上有一个字体:yizhen20133868/fonts

在terminal中执行以下代码:

打开terminal的偏好设置-描述文件,点击字体的“更改…”左上角设置按钮有个“管理字体…”,将刚刚安装的字体导入,然后在更改字体为刚刚导入的那个字体,我选择的是 Meslo LG S DZ Regular for Powerline 字体

然后就愉快的解决了这个问题……不会是问号,而变成箭头了~

1145. Hashing – Average Search Time (25) – 甲级

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average search time (the number of comparisons made to find whether or not the key is in the table). The hash function is defined to be “H(key) = key % TSize” where TSize is the maximum size of the hash table. Quadratic probing (with positive increments only) is used to solve the collisions.
Note that the table size is better to be prime. If the maximum size given by the user is not prime, you must re-define the table size to be the smallest prime number which is larger than the size given by the user.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive numbers: MSize, N, and M, which are the user-defined table size, the number of input numbers, and the number of keys to be found, respectively. All the three numbers are no more than 104. Then N distinct positive integers are given in the next line. All the numbers in a line are separated by a space and are no more than 105.
Output Specification:
For each test case, in case it is impossible to insert some number, print in a line “X cannot be inserted.” where X is the input number. Finally print in a line the average search time for all the M keys, accurate up to 1 decimal place.
Sample Input:
4 5 4
10 6 4 15 11
11 4 15 2
Sample Output:
15 cannot be inserted.
2.8

题目大意:给定一个序列,用平方探测法解决哈希冲突,然后给出m个数字,如果这个数字不能够被插入就输出”X cannot be inserted.”,然后输出这m个数字的平均查找时间
分析:先找到大于tsize的最小的素数为真正的tsize,然后建立一个tsize长度的数组。首先用平方探测法插入数字a,每次pos = (a + j * j) % tsize,j是从0~tsize-1的数字,如果当前位置可以插入就将a赋值给v[pos],如果一次都没有能够插入成功就输出”X cannot be inserted.”。其次计算平均查找时间,每次计算pos = (a + j * j) % tsize,其中j <= tsize,如果v[pos]处正是a则查找到了,则退出循环,如果v[pos]处不存在数字表示没查找到,那么也要退出循环。每次查找的时候,退出循环之前的j就是这个数字的查找长度。最后ans除以m得到平均查找时间然后输出~

PAT 1147. Heaps (30) – 甲级

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min heap) the key of C. A common implementation of a heap is the binary heap, in which the tree is a complete binary tree. (Quoted from Wikipedia at https://en.wikipedia.org/wiki/Heap_(data_structure))
Your job is to tell if a given complete binary tree is a heap.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers: M (<= 100), the number of trees to be tested; and N (1 < N <= 1000), the number of keys in each tree, respectively. Then M lines follow, each contains N distinct integer keys (all in the range of int), which gives the level order traversal sequence of a complete binary tree.
Output Specification:
For each given tree, print in a line “Max Heap” if it is a max heap, or “Min Heap” for a min heap, or “Not Heap” if it is not a heap at all. Then in the next line print the trees postorder traversal sequence. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line.

Sample Input:
3 8
98 72 86 60 65 12 23 50
8 38 25 58 52 82 70 60
10 28 15 12 34 9 8 56
Sample Output:
Max Heap
50 60 65 72 12 23 86 98
Min Heap
60 58 52 38 82 70 25 8
Not Heap
56 12 34 28 9 8 15 10

题目大意:给一个树的层序遍历,判断它是不是堆,是大顶堆还是小顶堆。输出这个树的后序遍历~
分析:30分大题,25行代码,一行代码一分……((⊙o⊙)嗯) // 我为什么这么机智可爱又伶俐?
从后往前检查所有节点(除了根节点)和它的父节点的关系,判断是否破坏最大堆或者最小堆的性质,如果有不满足的情况将maxn或minn置为0,以此排除最大堆或者最小堆~

然后后序遍历,对于index结点分别遍历孩子index*2和右孩子index*2+1,遍历完左右子树后输出根结点~

GPLT L2-026. 小字辈

本题给定一个庞大家族的家谱,要请你给出最小一辈的名单。
输入格式:
输入在第一行给出家族人口总数 N(不超过 100 000 的正整数) —— 简单起见,我们把家族成员从 1 到 N 编号。随后第二行给出 N 个编号,其中第 i 个编号对应第 i 位成员的父/母。家谱中辈分最高的老祖宗对应的父/母编号为 -1。一行中的数字间以空格分隔。
输出格式:
首先输出最小的辈分(老祖宗的辈分为 1,以下逐级递增)。然后在第二行按递增顺序输出辈分最小的成员的编号。编号间以一个空格分隔,行首尾不得有多余空格。
输入样例:
9
2 6 5 5 -1 5 6 4 7
输出样例:
4
1 9

分析:v[i]中保存i的所有孩子结点,root为家谱中最高辈分的老祖宗,从root开始向下深度优先搜索,求得maxlevel和最后一层的结点编号,保存在set里,最后输出maxlevel和set中所有数字~

 

PAT 1144. The Missing Number (20) – 甲级

Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.
Output Specification:
Print in a line the smallest positive integer that is missing from the input list.
Sample Input:
10
5 -25 9 6 1 3 4 2 5 17
Sample Output:
7

题目大意:给n个数字,找到不在这个数字列表里面的最小的正整数
分析:将每个数字出现的次数存储在map里面,num从1开始,如果m[num] == 0说明不存在,则输出这个num~

 

1085. PAT单位排行 (25) -PAT乙级真题

每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜。本题就请你实现这个功能。
输入格式:
输入第一行给出一个正整数N(<=105),即考生人数。随后N行,每行按下列格式给出一个考生的信息:
准考证号 得分 学校
其中“准考证号”是由6个字符组成的字符串,其首字母表示考试的级别:“B”代表乙级,“A”代表甲级,“T”代表顶级;“得分”是 [0,100] 区间内的整数;“学校”是由不超过6个英文字母组成的单位码(大小写无关)。注意:题目保证每个考生的准考证号是不同的。
输出格式:
首先在一行中输出单位个数。随后按以下格式非降序输出单位的排行榜:
排名 学校 加权总分 考生人数
其中“排名”是该单位的排名(从1开始);“学校”是全部按小写字母输出的单位码;“加权总分”定义为“乙级总分/1.5 + 甲级总分 + 顶级总分*1.5”的整数部分;“考生人数”是该属于单位的考生的总人数。
学校首先按加权总分排行。如有并列,则应对应相同的排名,并按考生人数升序输出。如果仍然并列,则按单位码的字典序输出。
输入样例:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
输出样例:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

分析:两个map,一个cnt用来存储某学校名称对应的参赛人数,另一个sum计算某学校名称对应的总加权成绩。每次学校名称string school都要转化为全小写,将map中所有学校都保存在vector ans中,类型为node,node中包括学校姓名、加权总分、参赛人数。对ans数组排序,根据题目要求写好cmp函数,最后按要求输出。对于排名的处理:设立pres表示前一个学校的加权总分,如果pres和当前学校的加权总分不同,说明rank等于数组下标+1,否则rank不变~
注意:总加权分数取整数部分是要对最后的总和取整数部分,不能每次都直接用int存储,不然会有一个3分测试点不通过~
PS: 更新后的pat系统会导致之前使用map的代码最后一个测试点超时,更改为unordered_map即可AC~