微软笔试
时间限制:C/C++ 1秒,其他语言 2秒
空间限制:C/C++262144K,其他语言524288K
64bit IO Format:%lld
本题可使用本地IDE编码,不能使用本地已有代码,无跳出限制,
编码后请点击”保存并调试“按钮进行代码提交。
■ 题目描述
【微软笔试第三道】
题目
Examples:
1.Given A=[1,1,3], B=[2,2,1] and S=3, the function should return true. We could assign patients in the following way:[123]where the K-th element of the array represents the number of the slot to which patient K was assigned. Another correct assignment would be[213] On the other hand,[2,2,1] would be an incorrect assignment as two patients would be assigned to slot 2.
2.Given A =[3,2,3,1], B=[1,3,1,2] and S=3, the function should return falseThere are only three slots availablebut there are four patients who want to visit the doctor.It is therefore not possible to assign the patients to the slots so that only one patient at a time would visit the doctor.
3.Given A=[2,5,6,5], B=[5,4,2,2] and S=8, the function should return true.For examplewe could assign patients in the following way: [5, 4,6,2].
4.Given A=[1,2,1,6,8,7,8], B=[2,3,4,7,7,8,7] and S=10, the function should return false.It is not possible to assign all of the patients to one of their preferred slots so that only one patient will visit the doctor during one slot.
Write an efficient algorithm according to the examples above.:
Golang
package Microsoft // you can also use imports, for example: // import "fmt" import ( "fmt" )
剩余50%内容,订阅会员后查看
此处内容需要权限查看
会员免费查看