USACO 3.3 TEXT Eulerian Tour中的Cows on Parade一点理解

Cows on Parade

Farmer John has two types of cows: black Angus and white Jerseys. While marching 19 of their cows to market the other day, John's wife Farmeress Joanne, noticed that all 16 possibilities of four successive black and white cows (e.g., bbbb, bbbw, bbwb, bbww, ..., wwww) were present. Of course, some of the combinations overlapped others.

农夫约翰有两种奶牛:一种是黑色的安古斯,一种是白色的泽西斯。当他在第二天驱赶他奶牛中的19只去市场时候,他的妻子女农场主乔安娜注意到16种所有4只黑白奶牛的顺序排列(例如:黑黑黑黑,黑黑黑白,黑黑白黑,黑黑白白,……,白白白白)都出现了。当然,一些排列是彼此覆盖的。

Given N (2 <= N <= 15), find the minimum length sequence of cows such that every combination of N successive black and white cows occurs in that sequence.

输入中有一个N(2 <= N <= 15),找到一串最小长度的黑白奶牛的排列包括N长度的所有的黑白奶牛顺序排列的情况。

Analysis: The vertices of the graph are the possibilities of N-1 cows. Being at a node corresponds to the last N-1 cows matching the node in color. That is, for N = 4, if the last 3 cows were wbw, then you are at the wbw node. Each node has out-degree of 2, corresponding to adding a black or white cow to the end of the sequence. In addition, each node has in-degree of 2, corresponding to whether the cow just before the last N-1 cows is black or white.

分析:这个图的顶点是n-1长度所有可能奶牛顺序排列。当你在一个顶点是相当你在这个奶牛颜色匹配串的最后n-1只奶牛。这也就是说,对于n=4,如果最后三只奶牛的颜色排列是【白黑白】,然后你正处于【白黑白】这个点。每个点有两个出度——相当于在这个串后面加白牛或黑牛。除此之外,每个点有两个入度——相当于这最后n-1只牛之前的颜色是黑的或白的。

The graph is strongly connected, and the in-degree of each node equals its out-degree, so the graph has a Eulerian circuit.

这个图是强连通的,并且每个图的入度等于每个点的出度,所以这个图有一个欧拉回路。

The sequence corresponding to the Eulerian circuit is the sequence of N-1 cows of the first node in the circuit, followed by cows corresponding to the color of the edge.

这个串就相当于最初的n-1只牛当回路起点的欧拉回路,后面跟着的牛就相当于边的颜色。

如果我跟英语老师说我在周末时间爱好翻译英文网页她会不会表扬我

我个人感觉,这道题翻译出来也是有一点不知所云的。

而且最后"边的颜色"稍微有点问题,因为这道题如果做欧拉不应该是记录边的,是记录点的,我把这道题的思路稍微改动一下,但是大意是不变的,方便理解。希望不是误解……

我们新建一个黑点b一个白点w,发现其实和分析里的描述是等价的一个具有欧拉回路性质的图。

寻找的过程可以抽象成这样,【wbw】后边加了一个b之后到了【bwb】,【wbw】后边加了一个w到了【bww】,然后做下去欧拉回路,相当于在n-1只黑白奶牛的全部可能的顺序排列后都加上b或w形成两个新的串,所以最后得到的回路串即为答案

但是我们既然每条边都要走一遍,那么经过黑点(或白点)到了哪个点已经没有关系了【因为我们所有点都是自己假定的,所以我们可以在我们的意识里假定wbw经过b后就是到的另一个点就是bwb因为路径一定会那么走过一遍的,丝毫不用考虑把这个编进程序】蓝字只是为了帮助理解

那么其实我们只要随便找一个n-1长的串,可以全部初始化为www,bbb之类的,放在前头,如题意建图,写欧拉回路就可以得解

显然,usaco里好像没有这道题……因为网上找不到这道题的题解……希望和我一样有耐心能读完那些英语材料最后碰到这个问题的人不会再懵逼了……

同时假如我们只需要输出长度,可以用这个意识流来证明一下,黑白两点各自经过2^(n-1)次,因为黑白两个点所以是2^n,最后加上n-1所以答案是(2^n)+n-1,n=4时答案是19和题中所叙述的是相同的

原文地址:https://www.cnblogs.com/ivorysi/p/6193949.html