Skip to content

ACM

今日头条笔试解题报告(10.17)

之前随便投了一下今日头条竟然过了,虽然不是很想去,但是已经给了我笔试邀约好歹也就做一下,锻炼锻炼脑子,说句实话还是挺喜欢头条的题目的,做起来很有以前ACM刷题的感觉,不像其他公司总感觉"工程化"比较多。

推箱子

第一题比较简单,表面上无从下手但是仔细想想应该能想出来的,本质上跟走迷宫问题本质上是一致的,只不过在这题中状态既要保存人的位置也要保存箱子的位置。暴力搜索能够,AC代码:

斐波那契堆之Go实现

一个比二叉堆更高效的数据结构,但是实现起来非常复杂。本科的时候看《算法导论》的时候曾经研究过,不是很明白。今天终于对它有了一个比较清晰的了解。 enter description here

Basic Algorithms in Go

最近学Go,感觉挺不错的。闲来无事用它写了几种常用的基础算法。

快排

思想很简单,实现起来为了方便每次以left作为基准,也可以使用BFS来节省递归栈:

// QuickSort returns a sorted slice
func QuickSort(arr []int) {
    if len(arr) <= 1 {
        return
    }
    left, right := 0, len(arr)-1
    for left < right {
        if arr[left+1] > arr[left] {
            arr[left+1], arr[right] = arr[right], arr[left+1]
            right--
        } else {
            arr[left+1], arr[left] = arr[left], arr[left+1]
            left++
        }
    }
    QuickSort(arr[:left])
    QuickSort(arr[left+1:])
}

ZOJ month contest D.Determinant and Matrix


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Description

Recently, LBH is learning the curse linear algebra. Thus he is very interested in matrix and determinant now. In order to practice his ability of solving the problem of linear algebra, he just invent some problems by himself. Once the problems was create, he would solve it immediately. However, he meet a problem that was so hard that he couldn't work out even though racked his brains. The problem was described as follow:

To a integer martix Mnn(aij), we define two function add(Mnn(aij))=Mnn(aij + 1) and sub(Mnn(aij))=Mnn(aij - 1) which were exactly like this:

baylor 6622 Absurdistan Roads( NWERC Contest)

原题pdf:click here

Description

The people of Absurdistan discovered how to build roads only last year. After the discovery, every city decided to build their own road connecting their city with another city. Each newly built road can be used in both directions.

Absurdistan is full of surprising coincidences. It took all N cities precisely one year to build their roads. And even more surprisingly, in the end it was possible to travel from every city to every other city using the newly built roads.

FFT求快速卷积的思考

离散型卷积的定义是:$$y(n)=\sum_{m=0}^{n} x(m)h(n-m)$$

注意,h函数是反转的。

在Chipher Messages一题中,b串需要反转再与a串匹配。

比如说:

a串: 110110110,则:

b`串:1011<------这里才是原来b串的头。但是向上对应到a串时,已经是m-1这个位置了。所以说,小于m-1的卷积是没有意义的。

于是,base=m。整体匹配。

(转)关于卷积的一个血腥的讲解,看完给跪了

比如说你的老板命令你干活,你却到楼下打台球去了,后来被老板发现,他非常气愤,扇了你一巴掌(注意,这就是输入信号,脉冲),于是你的脸上会渐渐地(贱贱地)鼓起来一个包,你的脸就是一个系统,而鼓起来的包就是你的脸对巴掌的响应,好,这样就和信号系统建立起来意义对应的联系。下面还需要一些假设来保证论证的严谨:假定你的脸是线性时不变系统,也就是说,无论什么时候老板打你一巴掌,打在你脸的同一位置(这似乎要求你的脸足够光滑,如果你说你长了很多青春痘,甚至整个脸皮处处连续处处不可导,那难度太大了,我就无话可说了哈哈),你的脸上总是会在相同的时间间隔内鼓起来一个相同高度的包来,并且假定以鼓起来的包的大小作为系统输出。好了,那么,下面可以进入核心内容——卷积了!

Timus 1996 Cipher Message 3 KMP+FFT求卷积

题目链接:click here

description

Emperor Palpatine has been ruling the Empire for 25 years and Darth Vader has been the head of the Empire Armed Forces. However, the Rebel movement is strong like it never used to be. One of the rebel leaders, Princess Leia from Alderaan, managed to get hold of secret blueprints of the Death Star, the imperial war station.

The Princess was going to deliver the station plan to the secret base for further analysis and searching for vulnerable spots. But her ship was attacked by the space destroyer "Devastator" headed by Darth Vader. At the last moment Princess Leia managed to send her findings to one of the closest planet called Tatooine with her droid R2-D2. Quite conveniently, an old friend of her father Obi-Wan Kenobi lives on that planet.

R2-D2 realizes the importance of his mission. He is going to encrypt the information so that the wrong people won’t get it.

ACM International Collegiate Programming Contest Asia Regional Contest, Tokyo Problem D Space Golf

原题 pdf:click here


日本的亚洲区域赛真心简单啊。两个小时就刷了 5 题有余了。排名第一的队伍才做出 7 道。

题目真心长的可以了,看了半个小时才明白。。

题意其实也就是太空中向前方抛小球,问小球能够穿过 N 个障碍物后到达制定地点的最小初始速度是多少。非常暴力的模拟题。离散化后直接枚举弹跳的次数再取最小值即可。注意 45° 方向能成功的话,那还是 45° 最优。