呃,都一年多没更新文章了,哈哈...后来想想还是多记录点东西,一来对自己的提高有帮助,二来就当是收集自己的代码库了 :)
因为过年,好几次没参加SRM了,最近又在看C++的东西,忽然用起VS来不那么顺手了~
Problem Statement
You recently got a job at a company that designs various kinds of filters, and today, you've been given your first task. A client needs a filter that accepts some objects and rejects some other objects based on their size. The requirements are described in the int[] sizes and the string outcome. If character i in outcome is 'A', then all objects of size sizes[i] must be accepted, and if character i is 'R', then all objects of size sizes[i] must be rejected. If an object's size does not appear in sizes, then it doesn't matter if it is accepted or rejected.
Unfortunately, your knowledge of filters is very limited, and you can only design filters of one specific kind called (A, B)-filters. Each such filter is characterized by two integers A and B. It accepts an object if and only if its size is between A and B, inclusive. You have excellent (A, B)-filter construction skills, so you can construct any such filter where 1 <= A <= B.
If it is possible to construct an (A, B)-filter that fulfills all the requirements described in sizes and outcome, return a int[] containing the filter's parameters, where element 0 is A and element 1 is B. If there are several appropriate filters, choose the one that minimizes B - A. If there are no suitable filters, return an empty int[].
Definition
Class: Filtering
Method: designFilter
Parameters: int[], string
Returns: int[]
Method signature: int[] designFilter(int[] sizes, string outcome)
(be sure your method is public)
Constraints
- sizes will contain between 1 and 50 elements, inclusive.
- Each element of sizes will be between 1 and 100, inclusive.
- All elements of sizes will be distinct.
- outcome will contain the same number of characters as the number of elements in sizes.
- Each character in outcome will be 'A' or 'R'.
- outcome will contain at least one 'A' character.
Examples
0)
{3, 4, 5, 6, 7}
"AAAAA"
Returns: {3, 7 }
Any filter with A <= 3 and B >= 7 will work in this case. Among them, A = 3 and B = 7 gives the minimal difference of B - A.
1)
{3, 4, 5, 6, 7}
"AARAA"
Returns: { }
This is similar to the previous example, but objects of size 5 need to be rejected. It's impossible to achieve this using a single (A, B)-filter.
2)
{3, 4, 5, 6, 7}
"RAAAA"
Returns: {4, 7 }
However, it's possible to reject only objects of size 3.
3)
{68,57,7,41,76,53,43,77,84,52,34,48,27,75,36}
"RARRRARRRARARRR"
Returns: {48, 57 }
4)
{26,81,9,14,43,77,55,57,12,34,29,79,40,25,50}
"ARAAARRARARARAA"
Returns: { }
概述
就是过找出一个区间,在这个区间内包含所有被接受的数字(即用A表示的)。
代码
本文介绍了一种特定类型的过滤器——(A,B)-过滤器的设计方法,该过滤器可以根据预设的大小范围接受或拒绝对象。通过分析给定的大小集合和期望的接受/拒绝结果,文章提供了一个算法实现,旨在找到能够满足这些需求的最佳过滤器参数。

1万+

被折叠的 条评论
为什么被折叠?



