pytorch++
Grad-CAM
使用方法
1 | from pytorch_grad_cam import GradCAM, ScoreCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM |
t-SNE:可视化降维算法
t-SNE介绍
- t-SNE是由t-分布和随机近邻嵌入(Stochastic neighbor Embedding)组成
- 其重要用途是 可视化和探索高维数据。它的主要目标是将高维数据集转换为低维数据集,并且可视化效果更好。采用非线性降维技术,可以捕获复杂的流行数据。
t-SNE工作原理
SNE算法
在介绍t-SNE之前,我们先介绍SNE算法
核心思想:
数据降维时,要保证: 在高维空间相似的数据点,映射到低维空间也是相似的。常规做法是使用欧式距离来表示这种相似性,而SNE把距离关系转换成一种条件概率来表示相似性
把距离映射到某一概率分布上:
对于高维空间中的两个点$x_i$,$x_j$, $x_i$以条件概率$p_{j|i}$选择$x_j$作为它的临近点。 考虑以$x_i$为中心点的高斯分布,如果$x_j$越靠近$x_i$,则条件概率$p_{j|i}$越高,相似性越高。
在SNE中,在高维空间中,条件概率$p_{j|i}$定义为
$$
p_{j|i} = \frac{exp(-||x_i-x_j||^2/{2\sigma_i^2})}{\sum_{k \neq i} exp(-||x_i - x_k||^2 /{2\sigma^2_i)}}
$$
考虑其它所有点与$x_i$的条件概率分布,可以构成一个条件概率分布$P_i$.
同样的,当数据映射到低维空间之后,我们也用类似上面条件概率的形式,定义低维空间中两点的相似性.
这里我们假设高维数据点$x_i,x_j$在低维空间中的映射点分别是$y_i,y_j$。类似的,低维空间中的条件概率用$q_{j|i}$表示,这里$\sigma$均固定为$1/\sqrt{2}$
$$
q_{j|i} = \frac{exp(-||y_i-y_j||^2/{2\sigma_i^2})}{\sum_{k \neq i} exp(-||y_i - y_k||^2 /{2\sigma^2_i)}}
$$
考虑其它所有点与$y_i$的条件概率分布,可以构成一个条件概率分布$Q_i$.
高维空间的条件概率分布$P_i$应该和低维空间中的概率分布$ Q_i$相同,我们可以用KL散度来衡量两个分布之间差异。
SNE的最终目标就是对所有数据点最小化KL距离,其代价函数可以定义为
$$
C = \sum_{i} KL(P_i || Q_i) = \sum_{i} \sum_{j} p_{j|i} log \frac{p_{j|i}}{q_{j|i}}
$$
不过目前的SNE存在两个问题:不对称 和 拥挤问题
- 不对称:$p_{j|i}$ 和 $q_{j|i}$不相等
- 拥挤:不同类别的簇挤在一起,没有办法分开。因为高维空间距离分布和低维空间存在差异。简单来说,更高维的空间距离相等的点的数据量更多。在10维流行性,存在11个点两两数据相等,而在2维空间,最多能使3个点之间两两数据相等。所以将高维空间中的距离关系完全保留到低维空间中是不可能的.
t-SNE算法
针对上述提到的SNE算法中的两点不足,t-SNE提出了相应的解决方法。
不对称
对于不对称问题,我们用更加简答直观的方式重新定义了概率分布
$$
p_{ij} = \frac{p_{i|j} + p_{j|i}}{2n}
$$
相应的损失函数可以定义为
$$
C = KL(P||Q) = \sum_{i} \sum_{j} p_{ij} log\frac{p_{ij}}{q_{ij}}
$$
相应的梯度变为:
$$
\frac{\grad C }{ \grad{y_i}} = 4 \sum_{j}(p_{ij} - q_{ij})(y_i-y_j)
$$
拥挤
随着维度的增加,大部分数据点与$x_i$之间的距离分布极其不均衡,很多点与$x_i$之间的距离接近,如果直接把高维距离关系保留到低维空间。很容易出现拥挤问题。我们用t-分布的方法,解决该问题。
t-分布
t-分布:从正态总体中抽取容量为N的随机样本,如果该正态总体的均值为$\mu$,方差为$\sigma^2$.随机样本均值为$\hat x$,方差为$s^2 = \frac{1}{N-1} \sum_{i=1}^{N} (x_i - \hat x)^2$,
随机变量t可以表示为
$$
t = \frac{\hat x - \mu}{ s / \sqrt{N} }
$$
我们称t服从自由度为n-1的t分布。
t-分布是长尾分布。相比于高斯分布,他尾部更宽一些,处理小样本和异常点时,鲁棒性较高
![](/.com//08/02/t-SNE-%E5%8F%AF%E8%A7%86%E5%8C%96%E9%99%8D%E7%BB%B4%E7%AE%97%E6%B3%95/20210802161150.png)
如上图所示,要是$p_{ij}$ 和$q_{ij}$相等,在高维空间中比较接近的点(对应正态分布),在低维空间中要更接近(对应t-分布);而对与高维空间中较远的点,在低维空间中需要更远。
所以在t-SNE中,用t-分布,重新定义了低维空间中的概率分布,如下所示
$$
q_{ij} = \frac{(1+||y_i - y_j||^2)^{-1}}{ \sum_{k\neq l}(1+||y_k - y_l||^2)^{-1}}
$$
代码实现
“封装成一个函数”
1 | import numpy as np |
“应用实例”
使用时,需要自己计算colorlis
1 | from PIL import Image |
运行结果
![](/.com//08/02/t-SNE-%E5%8F%AF%E8%A7%86%E5%8C%96%E9%99%8D%E7%BB%B4%E7%AE%97%E6%B3%95/20210803133641.jpg)
面试英语问题总结
友情链接:
研究生面试常见问题(英文+中文) - 知乎 (zhihu.com)
自己被问到过的
北深:
你觉得ai十年后会发展成什么样子?
中科大:(当时问了超级多的内容,问到快排的时候,我都懵了==)
自我介绍,介绍一下家乡(河南),兴趣爱好,介绍一些自己较好的学习习惯(写博客),简单解释一下快排的含义,介绍一下U-net结构
研究生计划
Thanks for the question!
I am planning it based on my interest and theoretical foundation.First, I will make reasonable arrangements according to the curriculum, with particular attention on the study of basic theory and methodology in my field. In my spare time, I may read various books regarding ai and compuer vision regularly.Try to put forward creative ideas and new opinions,so that I can better communicate with my professors and counterparts.
Then,assisting my instructor with his/her work is very important and I believe it a great way to make progress. If possible, I hope to attend some academic seminars and publish a paper with high quality under the guidance of my adviser.At last, I want to have my English ability consistently improved ,which is beneficial to paper-reading ,you know.
If I can be accepted ,I will start my postgraduate plan very soon in my rest of college time,like reading classical academic work and paper to cultivate independent thinking and research ability.I am looking forward to realizing my dream here!
个人介绍
I’m very honored to be here to present myself.I am sherry wang, a twenty-two years-old girl. I’ll graduate from JLU and my major is CS.
During my college life, I have worked very hard at my courses.So that I have achieved excellent grades in major courses.The GPA for the first five semeters is 3.86.I also have passed CET-6 smoothly.
Apart from that.I have participated in various scientific research.One of the most satisfying is the landmark detection of human joints system. And at present, our system has been applied to the clinic, and is welcomed by doctors.I’m the leader and responsible for the implementation of the system algorithm. Those progress were a little difficult, but I learned a lot from them. And it was those experience that inspired my interest in adamic research.
I think my search and study in the undergraduate stage is colorful but shallow .So I hope to have a chance to study here.I’ll spare no effort to do research in my major.
Thanks for your attention!
介绍学校
JLU is founded in 1946 and located in Changchun,China. As a leading national research university , It’s strongly supported by state key projects such as Project 985 and Project 211.
It has seven campuses in six districts that are home to 47 colleges covering 13 academic disciplines, including philosophy, economics, law, literature, education, history, science, engineering, agriculture, medicine, management, military science and art.
And JLU is very beautiful. There are lots of flowers, plants, and the air is very fresh. The teachers are very responsible and the students are energetic. I learned a lot and made great progress. I am very grateful to my college , because it makes me better.
In a word,I enjoy the past three years spend in JLU very much !
介绍家乡
Changchun, my hometown, sits in the hinterlands of the Song Liao plain of Northeast China. It is the capital city of Jilin Province. Here is the most fertile soil in China. When you are walking on this modern and civilized city, you cannot fail to feel the vitality and prosperity of this city.
介绍长春
Changchun sits in the hinterlands of the Song Liao plain of Northeast China. As the capital city of Jilin Province, it is the economic and cultural center of the whole province. And it is famous for its developed automobile industry. Here is the most fertile soil in China. When you are walking on this modern and civilized city, you cannot fail to feel the vitality and prosperity of this city.
It still enjoys great reputation for culture. There are not only rich varieties of modern entertainment facilities, but also some special entertainment items only for Changchun, such as Yangge Dance and Errenzhuan, which is a song-and-dance duet in the Northeast of China.
If you have the opportunity of doing some sightseeing in Changchun, I recommend you to taste my hometown’s specialties.There are two kinds of famous dishes in Northeast China: Stewed young chicken with mushroom and Stewed Pork with Vermicelli.
做的项目遇到困难最多的是什么? 你是如何克服的
What impressed me the most is the distributed development course in the first semester of the junior year.
This course is a synchronized course with a school in Portugal, we need to complete a medical assistant software system.
I am the leader of the group. Our group is responsible for the development of deep learning algorithms and completes the task of detecting key points of medical x-ray image.
Encountered the following problems
- In terms of communication and cooperation, the group members include students from Portugal and China. Due to language and time difference issues, it is not very convenient for us to communicate.
In order to solve this problem, we communicated in various ways through WeChat and email, and developed using github.
The members are more serious and enthusiastic, so our project development is very smooth.- In terms of technology, you know, the algorithm is the core of the project and affects the performance of the software.
Initially, we had no idea how to complete the key point detection task.
Later, after checking literature, reading papers, group discussions, asking teachers for opinions, etc., an algorithm with a relatively high accuracy rate was designed.I learned a lot from it.
cooperation and communication is importrant for team work. Team members should have a common goal and work hard for it . As a leader, I should be gentle and kind, and very responsible. I always encourages everyone to share their opinions.
I learn how to solve a problem in a better way.
First of all, you must analyze the problem to be solved, draw up a preliminary idea,
Then, check the literature, ask teachers and classmates, and further determine the detailed solution.
In this process, the most important thing is that the team must be creative and good at rigorous thinking.
选择本校读研的原因
Thanks for your question!
Well, what attracts me most is your resounding influence in the field of CS and AI . During my undergraduate period, I have shown some interest in AI and tried to pursue further study in this area. As I know, this is the predominant part in your school. And, you have so many excellent teachers and I want to be guided by them in theory and practice.
Location is another critical factor prompting my decision. Beijing, as the capital city of China, has provided various study and work resources for our young people, which I would never have thought without coming here. Though I may be encountered with fierce competition and harsh challenges, I still like to embrace its vigor and vitality.
The last one I want to say, this is a comprehensive university, which,I believe, can give students comparatively all- round development. I’m looking forward to studying here!
自己的优缺点
Well,Thanks for the question!
In my view, I’m a pragmatic person(务实的),willing to focus on the current thing and optimize it. Recalling my undergraduate times when I was doing some research or finishing some task, I would always amend them for many times until I’m totally satisfied. I can bear hardships(克服困难) and cooperate well with other people, with all the makings of awell-done job.This may be trained by the teamwork and practice inside and outside the campus.
Nobody is perfect.I can never eschew my shortcomings. As a matter of fact, I‘m not good at time management, which may result from my insistence on one thing,I guess.Sometimes,when I’m immersed in my task,I will not stop it until it has been completed. As a result, my schedule is often tight, sometimes losing balance between life and study. I am trying hard to get over with this and act myself decisively and effectively.
最喜欢的书/专业课
最喜欢读的书
Up to now I have read a lot of books, for example,magazines,novels and storybooks and so on.But one of the books that I like best is My Life Story.It was created by an American writer—Helen Keller in 1902.She was a blind,deaf and dumb person.In the book,she wrote that she had not been able to see,hear or speak since the age of one year and seven months.This unusual thing made her very sad.When she was seven years old,she knew Miss Sullivan,her good teacher.Helen was getting happier every day.Then,Miss Sullivan helped her learn how to write English words.At first,Miss Sullivan wrote some words on Helen’s hands with her own fingers again and again.Helen was a very diligent girl.Because of this,she tried as much as possible to remember words.After that,she wrote and published many famous works.My Life Story is one of them.
Therefore, when I select a team in the future, responsibility and the efficiency of teamwork will be the main elements for me. Only fighting side by side can bring success.
My Life Story described her hard struggle to become an outstanding writer and educationist of the world. It shows us a universal truth:“Nothing is difficult if you put your heart intoit!”This is why I like it best.
最喜欢的课程是编译原理
Compilation principle is an important professional course for computer majors, which aims to introduce the general principles and basic methods of compiling program construction.
The content includes language and grammar, lexical analysis, grammatical analysis, grammar-guided translation, intermediate code generation, storage management, code optimization and target code generation.
The interesting and challenging course content has made me gain a lot.I learned hwo to code a compiling program.
It’s amazing!
AI的含义,应用,发展趋势,发展难点,应用案例之类的
The full name of AI is artificial intelligence, which can be explained as machines that are built to act and behave like human, contains features of human like facial recognition, voice recognition, decision making, vision system etc.
发展趋势&& 发展难点
At present, AI has the following problems
Data cost, a successful and effective deep learning network requires massive data support.
The interpretability of the model.
At present, most machine learning models are “black box” models, which are difficult for people to understandAs for development trend, I think there two points as follow:
- AI chips development
Even fast and advanced CPUs cannot increase the speed of AI models. It is necessary to develop smaller and more powerful embedded chips to run better algorithms for real-time tracking, facial recognition and other applications.
- AI edge computing and integrated development of the Internet of Things
I n short, many AI research results have profoundly changed people’s lives. In the future, the development of AI will be faster and will have a greater impact on people’s lives, work and education.
他们的未来是什么?
One of the future trends of computer science is artificial intelligence, which is the study and artificial simulation of human thoughts, which will eventually enable machines to think like humans. Serve humanity and help people solve problems.
After all, people thought it was unique, there are feelings, there are a variety of character, this will be very difficult to achieve in the machine.In fact, to do the same as the human thinking machine, the only one of the artificial intelligence, is by no means all. Through the study of artificial intelligence, can resolve all kinds of scientific problems, and promote the development of other science, the artificial intelligence is the best!
I believe that the science of artificial intelligence is waiting for humanity to explore it step by step the real connotation.’
描述你参加过的最好的/最差的团队
The best team I have ever participated in is the Law School Society during my undergraduate study. This is a very warm collective. As a whole, we have a common goal, and everyone works hard for it.At the same time, we have a very good leader, he is gentle and kind, and very responsible. He always encourages everyone to share their opinions, we often have brainstorm, and he will use his experience and vision to help us summarize to find the best way. After the leader assigns the tasks, each of us will actquickly, and the strong action makes the team efficient, so the activities orprojects held by us are always exceptionally successful. Everyone in the society is proud of it.
In contrast, I have participated in acharity team with the goal of helping the old people who have no children to take care of them. However, the people involved in this team do not have enough responsibility. The activities are often to be half-finished. The leaders in the team often find various reasons to cover up their mistakes. Members always don’t take their tasks seriously. The whole team is in disarray.
Therefore, when I select a team in the future, responsibility and the efficiency of teamwork will be the main elements for me. Only fighting side by side can bring success.
专业问题
快速排序
Quicksort is a divide-and-conquer algorithm. It works by selecting a ‘pivot’ element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. For this reason, it is sometimes called partition-exchange sort.[4] The sub-arrays are then sorted recursively. This can be done in-place, requiring small additional amounts of memory to perform the sorting.
Mathematical analysis of quicksort shows that, on average, the algorithm takes O(n log n) comparisons to sort n items. In the worst case, it makes O(n2) comparisons, though this behavior is rare.
hash
In computing, a hash table (hash map) is a data structure that implements an associative array abstract data type. It can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found. During lookup, the key is hashed and the resulting hash indicates where the corresponding value is stored.
In many situations, hash tables turn out to be on average more efficient than search trees or any other table lookup structure. For this reason, they are widely used in many kinds of computer software, particularly for associative arrays, database indexing, caches, and sets.
U-net
Unet原文
It consists of a contracting path (left side) and an expansive path (right side). The contracting path follows the typical architecture of a convolutional network. It consists of the repeated application of two 3x3 convolutions (unpadded convolutions), each followed by a rectified linear unit (ReLU) and a 2x2 max pooling operation with stride 2 for downsampling. At each downsampling step we double the number of feature channels. Every step in the expansive path consists of an upsampling of the feature map followed by a 2x2 convolution (“up-convolution”) that halves the number of feature channels, a concatenation with the correspondingly cropped feature map from the contracting path, and two 3x3 convolutions, each followed by a ReLU. The cropping is necessary due to the loss of border pixels in every convolution. At the final layer a 1x1 convolution is used to map each 64- component feature vector to the desired number of classes. In total the network has 23 convolutional layers.
笔试专业课知识点总结
计算机网络
![image-20210704143335093](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704143335093.png)
数据链路层
介质访问控制子层:主要任务是为每个节点隔离来自同一信道上其它节点所传送的信号,以调节活动节点的传输。
常见的介质控制方法有:信道划分介质访问控制,随机访问介质访问控制和轮询访问介质访问控制,
CSMA协议(carrrier sense multiple access)
CSMA/CD:
发送前先侦听,等待信道变为空闲时再发送,碰撞检测就是边发边侦听,如果遇到碰撞时,就发送一个48bit的拥塞信号
”先听后发,边听边发“
适用于总线型网络或者半双工网络。
最小帧长的计算:
原理是 因为是边发边侦听,所以要确保发送站在发送数据的同时,能检测可能存在的冲突,需要在发送完帧之前能够收到自己发送出去的数据(对方发出的拥塞信号)
1 | 最小帧长 = 2* 总线传播时延 * 数据传输率 |
CSMA/CA协议
适用于无线网络。
TCP 流量控制和差错控制
![image-20210704152537844](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704152537844.png)
-==流量控制:是一个速度匹配服务,匹配发送方的发送速率和接收方的读取速率==
-==TCP 拥塞控制: 是为了防止过多的数据注入网络,保证网络中的路由器或链路不致过载。拥塞往往表现为通讯时延的增加。==
流量控制和差错控制的共同点:都是可以通过控制发送方发送数据的速率来达到控制效果。
区别在于 拥塞控制是为了让网络能够承受现有的网络负荷,是一个全局性的过程,涉及所有的主机,所有的路由器以及降低网络传输性能的有关因素;相反流量控制只是单纯的 接收端控制发送端。
TCP拥塞控制算法: 慢开始,拥塞避免,快重传,快恢复。
Http协议
数据结构
关于排序算法
元素移动次数与关键字的初始排列次序无关的是:基数排序
元素比较次数与关键词的初始序列无关的是 选择排序
算法的时间复杂度与初始序列无关的是 选择排序
KMP算法
二叉树
![image-20210704220113711](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704220113711.png)
计算机组成原理
浮点运算
![image-20210704184909217](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704184909217.png)
Cache结构
![Snipaste_2021-07-04_19-54-40](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/Snipaste_2021-07-04_19-54-40.png)
cache地址映射
cache结构: 标记项|数据项
标记项:标记地址+有效位+脏位(可选,写回法)+替换计数位(可选)
直接映射方法
直接映射的地址结构: 标记地址+cache块号+块内地址
全相联映射
组相联映射
Cache中替换算法和写策略
![image-20210704200754536](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704200754536.png)
写策略
命中时,
写直达:对cache写命中时,必须把数据同时写入主存中。
写回法:只修改cache中,不立即写回,之后被换出时,写回到主存
非命中时
写分配:加载主存中的块写到cache中,然后之后更新主存中的块
写不分配:直接写到主存中,不加载到内存中
访问冲突
![image-20210704200306480](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704200306480.png)
内存地址计算
内存地址 = 基址寄存器+形式地址
![image-20210705140249579](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210705140249579.png)
操作系统
中断
![image-20210704202347114](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704202347114.png)
死锁
![image-20210704212020783](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704212020783.png)
死锁的4个必要条件:资源独占,不可剥夺,保持申请,循环等待
① 资源独占。一个资源在同一时刻只能被分配给一个进程。如果某一进程申请某一资源,该资源正在被另外的某一进程所占有,则申请者需要等待,直到占有者释放该资源。
② 不可剥夺。资源申请者不能强行地从资源占有者手中夺取资源,即资源只能由其占有者在使用完后自愿地释放
③ 保持申请。进程在占有部分资源后还可以申请新的资源,而且在申请新资源的时候并不释放它已经占有的资源。
④ 循环等待。存在一个进程等待序列{p1, p2,…, pn},其中 p1 等待 p2 所占有的某一资源,p2 等待 p3 所占有的某一资源……pn 等待 p1 所占有的某一资源。
死锁处理:死锁预防,死锁避免,死锁恢复,死锁检测
- 死锁预防
- 对进程有关的资源活动加以限制,所有进程遵循这种限制,即可保证没有死锁发生。
- 优点: 简单,系统不需要做什么。 缺点: 对进程的约束比较难保证,如果违反时就有可能发生死锁
- 预先分配法[系统:如果可以满足,全部分配;否则一个也不分配,破坏保持请求的条件],
- 有序分配法[按照资源编号由小到大的次序申请资源,破坏循环等待条件]
- 死锁避免
- 它不会对于申请进程有关资源的命令施加任何限制,而是对于进程发出的每一个系统能够满足的资源申请命令实施动态检查,并根据检查结果决定是否==实施资源分配==。
- 银行家算法(Need数组,需要知道程序运行所需资源总量信息)
- 死锁检测(死锁已发生时,检测并解决)
- 死锁检测(在进程等待时检测,定时检测。。)
- 死锁恢复:资源剥夺法,进程撤销法,进程回退法(要求系统保持进程的历史信息)
缺页发生的调度
![image-20210704215043716](/.com//07/04/%E7%AC%94%E8%AF%95%E4%B8%93%E4%B8%9A%E8%AF%BE%E7%9F%A5%E8%AF%86%E7%82%B9%E6%80%BB%E7%BB%93/image-20210704215043716.png)
每日机试20210628
==感觉时间真的是不够了,呜呜呜,裂开都不够的
尽管在等通知的同时,自己很焦急(头都快炸了),还是要把该做的做好
今天没刷几道题目,感觉就是练练手,重新捡起来之前断掉的机试训练。
aa,还需要提醒的是,哈工深好像有笔试题目,自己要把简单的专业课给过一遍,计算之类的,能学多少是多少吧
/=\ 感觉机器学习数据挖掘之类的学习起来好有意思!!gg
在这里列一下我之后机试的计划
- 贪心算法(背包问题==我想起来之前参加pat时候遇到的问题)
- 动态规划
- KMP
- 大整数运算(一般作为签到题)
- 二分算法
- 之后就是针对院校进行机试
- https://github.com/youngyangyang04/leetcode-master
- N诺
- pat(按照前计划,柳神的代码可以学到好多)
加油!今天的收获
万能头文件
1
#include<bits/stdc++.h>
关于memset和fill的用法
数组
1 | //关于二维数组的初始化 |
vector
1 | fill(v.begin(), v.end(), 要填入的内容); |
- C/C++关于字符串的读取
题目:[日期差值]
这里需要判断闰年: 年份能够被100整除,同时被400整除; 能被4整除,但是不能被100整除
1 | bool isRui(long long y1){ |
1 | //利用char数组 |
动态规划经典题型的复习
==自己最开始忘记设置dp数组的边界,调试了好久
最大连续子序列和
LIS最长不下降子序列
LCS最长公共子序列
最长回文子串**可以多刷
分块思想
如何维护一个栈,可以在线取出其中第K大的元素
开坑线段树
vue基础
methods_弹窗
1 | <!DOCTYPE html> |
双向数据绑定
view 通过 <input
v-model
= “item”>将用户的输入绑定到名外item的数据上 通过,绑定显示后台名为item的数据
1 | <!DOCTYPE html> |
vue组件
用户自定义的结构
1 | <!DOCTYPE html> |
Axios异步通信
1 | <!DOCTYPE html> |
对应的json文件data.json
1 | { |
计算属性
计算属性的重点突出在属性两个字上,首先它是一个属性,其次它有计算的能力,这里计算
就是一个函数;它能够将计算结果缓存起来.
内存中执行,虚拟Dao
计算属性的主要特征就是为了将不经常变化的计算结果进行缓存,以节约我们的系统开销.
1 | <!DOCTYPE html> |
VUE插槽(slot)//内容分发
1 | <!DOCTYPE html> |
自定义事件
通过以上代码不难发现,数据项在Vue的实例中,但删除操作要在组件中完成,那么组件如何才能删除Vue实例中的数据呢?此时就涉及到参数传递与事件分发了,Vue为我们提供了自定义事件的功能很好的帮助我们解决了这个问题;
使用this.$emit (‘自定义事件名’,参数)
1 | <!DOCTYPE html> |
机试list
机试的难度
个人认为,机试难度可以分四个等级:
第一级,清北难度,能通过且取得不错成绩的很多都是打ACM竞赛的大佬,没受过专业训练很难拿高分,这个难度下题目很多都是ACM竞赛等级。不过北大的难度貌似没有那么高。
第二级,华五难度,题目涉及基础算法和数据结构,如果只会暴力算法无法通过机试,但如果你刷过一些算法和数据结构的题目,非低分通过机试应该不成问题。
第三级,基础难度,以北航华科为代表,题目涉及大量基础数据结构和编程细节,主要考察编程而非算法能力,个人认为接触过基础数据结构且编程细心的同学应该能够通过。但这些高校往往会限定标准C编程,这点还要注意。
第四级,不进行机试,以国防科大、中科院自动化所为代表,这些学校只有面试没有机试。
刷题
整理出一些典型题目或“板子”以备考前复习。
南大计算机 | 300分的题目一共三道题,每道题100分、通过样例点给分(每道题10个样例点),是在线OJ形式、可以看到自己的实时排名(和浙大类似),动态规划多一些 | 120以下的同学貌似被淘汰了、同学190都是专硕。 |
---|---|---|
浙大 | 三小时四道英文题,题目难度号称PTA甲级难度(实际难度是PTA乙级到甲级之间),题目分值是20,25,25,30这样.题目是OJ形式,根据通过的样例点得分,不计罚时,采用PTA的系统,能够看到自己的实时得分和排名 | |
中科大 | 机试和上交的机试形式差不多,都是非OJ形式。具体而言,三小时做五道算法题,开始的时候给你发纸质的题目和示例(中文),然后自己写程序自己想样例测试,最后工作人员拷走你电脑上的程序。题目采用C/C++,允许使用STL,编译器有VC,VS,code blocks, dev c++等。题目样例没有全通过的话最后会有老师阅卷打分,这点和北航一样。 |
2019 |
北航 | 题目采用C/C++,允许使用STL,编译器有VC,VS,code blocks, dev c++等。虽然之前的通知和宣讲会说最好是C标准编程,但实际上都是可以用的。然而北航的评测系统不是OJ形式,只能显示你提交的代码编译是否通过,具体能不能AC只能靠本地自己编用例测试了(所以一定要细心!!)。不过还好,如果你有一道题没有AC的话,老师会查看你的源代码,根据你代码体现的思想和编码习惯什么的给分,所以就算做不完也一定要记得提交呀! |
|
上交 | 上交的机试不是OJ形式的,而是发给你英文的纸质题目描述和一个样例(运行时间10s以内都ok),自己编写、本地调试,结束后由老师过来把源代码和可运行的exe文件拷走,可选择的编译器有VS/code blocks/DEV C++等 | |
北深 | ||
清深 |
参考: https://blog.csdn.net/qq_38633884/article/details/97178586
自动化所:问数学和机器学习多一些,自动化所只有面试没有机试
中科大的考核机制:学院机试+学院面试+课题组考核,其中学院的机试、面试小分和学院考核总成绩都达标即可获得优营资格,听过优营比例很高的,我们这届计算机夏令营貌似有六七十人
二分图模板题
https://www.cnblogs.com/shenben/p/5573788.html
位运算
找出只出现一次的数
给你一组整型数据,这些数据中,其中有一个数只出现了一次,其他的数都出现了两次,让你来找出一个数 。
所有的数进行异或
m的n次方
也可以参考快速幂的做法
1 | //快速幂的递归写法,复杂度为 logb |
找出不大于N的最大的2的幂指数
把N的二进制中最左边的 1 保留,后面的 1 全部变为 0, 如何实现?
ans=最左侧的1,eg: N=19 = 0001 0011, ans = 0001 0000
代码实现:
1 | int findN(int n){ |
上交
1 | 1. 给定两个英文单词,每次操作可以删去任一单词中的任一字母,求使两个单词最终一样的最少操作次数 |
面试数据结构总结
判断一个无向图是否是一棵树
树的定义是连通的有向无环图,所以需要判断图是否是连通而且没有环,一次dfs或者bfs即可,遍历时需要加访问标记,时间复杂度是O(V) //每条边都遍历了一次.
各种排序算法的稳定性,复杂度的对比,简单思路
高度k的树最少节点数
感觉不是很严谨,如果没有规定,树可以退化成链表,最少是k个点。
对于完全二叉树而言,高度为h的二叉树 2^h个结点,至少有 2^h 个结点
对于高度为h的m叉树至多包含 (m^h-1)/(m-1) 个结点。[等比数列]
哈夫曼编码(huffman code)
在含有n个带权叶结点的二叉树中,其中带权路径长度(WPL)最小的二叉树被称为哈夫曼树。
含有n个叶子结点的huffman树,一共有2n-1个结点,huffman中只包含叶子结点和度为2的点.
可以用堆来构造。,时间复杂度是O(nlogn)
构建过程
![2021-06-18_14-30](/.com//06/18/%E9%9D%A2%E8%AF%95%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%80%BB%E7%BB%93/2021-06-18_14-30.png)
huffman编码:
可变长编码,把字符出现的频率看作是结点的权重
后缀表达式
运算符紧跟在操作数的表达式,没有括号,运算符之间不存在优先级的差别,计算过程完全按照运算符出现的先后顺序进行。
中缀转后缀
后缀表达式计算
- 从左依次读取后缀表达式的一个符号
- 如果是操作数,则压栈
- 如果是运算符,则从栈中连续弹出两个元素,进行相应的运算,并将结果压入栈
- 如果读入的是结束符,则栈顶就是计算结。
快速排序的时间和空间复杂度
快速排序的核心思想是 partition操作(分治策略)
选取一个基准元素(pivot)
比pivot小的放到pivot左边,比pivot大的放到pivot右边
对pivot左边的序列和右边的序列分别递归的执行步骤1和步骤2
一次partition的时间复杂度是O(n). 当每次S(n)划分后,左右两个序列变成S(1)和S(n-1),快排退化成冒泡,时间复杂度变成O(n*n)
所以每次partition可以利用随机算法选择基准元素。
快排为什么会快?
在堆排序中,存在大量的随机存取(包括一些无效的swap操作),而在快速排序中,数组指针的移动都是在相邻的区域内的,符合空间局部性的特点,经常访问cache中的数据,cache比主存快的多。
堆及其应用
堆维护一个偏序关系,能够支持的操作是
1 | void up(int index); //尝试将index元素上浮 |
应用: 1.优先级队列 2.堆排序
时间复杂度//空间复杂度
时间:一个语句的频度是指该语句在算法中被重复执行的次数,算法中所有语句的频度之和记为T(n),它是该算法问题规模n的函数,时间复杂度主要是为了分析T(n)的数量级。
空间:算法所耗费的存储空间,它是该算法问题规模n的函数
算法的特点是:有限性,可行性,确定性,输入,输出.
广义表
NP和NPC问题
- P类问题:能在多项式时间内可解的问题。
- NP类问题:在多项式时间内“可验证”的问题。也就是说,不能判定这个问题到底有没有解,而是猜出一个解来在多项式时间内证明这个解是否正确。P类问题属于NP问题,但NP类问题不一定属于P类问题。
- NPC问题:存在这样一个NP问题,所有的NP问题都可以约化成它。换句话说,只要解决了这个问题,那么所有的NP问题都解决了。其定义要满足2个条件:
- 它是一个NP问题
- 所有的NP问题都可以规约到它
- NP-hard问题: 即所有的NP问题都能约化到它,但是他不一定是一个NP问题
![2021-06-18_16-14](/.com//06/18/%E9%9D%A2%E8%AF%95%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E6%80%BB%E7%BB%93/2021-06-18_16-14.png)
如何判断一个树是否是一个完全二叉树
通过层次遍历的方式:
基本思路是层次遍历该树,从第一个度不为2的结点开始,之后的结点的度都为0.