SRM 497(DIVII) 250 Filtering

呃,都一年多没更新文章了,哈哈...后来想想还是多记录点东西,一来对自己的提高有帮助,二来就当是收集自己的代码库了 :)

因为过年,好几次没参加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表示的)。

 

代码

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值