POJ2182 Lost Cows (树状数组+二分)
2021-04-25 22:27
标签:ring sample display 数组初始化 rand tin lin instead tab N (2 Input * Line 1: A single
integer, N Output * Lines 1..N: Each
of the N lines of output tells the brand of a cow in line. Line #1 of the
output tells the brand of the first cow in line; line 2 tells the brand of the
second cow; and so on. Sample Input 5 1 2 1 0 Sample Output 2 4 5 3 1 思路蓝书已经说得比较清楚了。大致就是从后往前确定。首先最后一头牛的身高必定等于An
+ 1,倒数第二头牛的身高要么等于An-1 + 1(当An-1
= An时),因为每头牛的身高都是互异的。以此类推,如果第k头牛前有Ak头牛身高比他低,那么它的身高就是1~n中第Ak + 1小的没有在已经确定的身高中出现的数,能看出来比较关键的思想就是避开已经存在的身高。由于身高都在1~n范围内且互不相同,因此可以开辟一个长度为n的01数组,初始化为1,然后从后往前遍历Ai,查询第Ai + 1个1的位置作为当前牛的身高,然后在树状数组中把这个位置归零即可。 注意数组初始化要用modify。 POJ2182 Lost Cows (树状数组+二分) 标签:ring sample display 数组初始化 rand tin lin instead tab 原文地址:https://www.cnblogs.com/lipoicyclic/p/13256013.html
Regrettably, FJ does not have a way to sort them. Furthermore, he‘s not very
good at observing problems. Instead of writing down each cow‘s brand, he
determined a rather silly statistic: For each cow in line, he knows the number
of cows that precede that cow in line that do, in fact, have smaller brands
than that cow.
Given this data, tell FJ the exact ordering of the cows.
* Lines 2..N: These N-1 lines describe the number of cows that precede a given
cow in line and have brands smaller than that cow. Of course, no cows precede
the first cow in line, so she is not listed. Line 2 of the input describes the
number of preceding cows whose brands are smaller than the cow in slot #2; line
3 describes the number of preceding cows whose brands are smaller than the cow
in slot #3; and so on. #include
文章标题:POJ2182 Lost Cows (树状数组+二分)
文章链接:http://soscw.com/index.php/essay/79540.html