找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2883|回复: 4
收起左侧

[面经题目讨论] 急问!编程实现数学运算相关面试题

[复制链接]

27

主题

4

精华

288

积分

高级会员

Rank: 3Rank: 3

积分
288
发表于 4-13-2015 11:07 AM | 显示全部楼层 |阅读模式

亲!马上注册或者登录会查看更多内容!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Alice has invented a new card game to play with Bob. Alice made a deck of 7 \! E: Q1 e& `/ a
cards with random values between 1 and 52. Bob picks 5 cards. Then, he has
) a, `! w& @) a1 C, Mto rearrange the cards so that by utilizing the operations plus, minus, or
9 \9 J0 h, z# G/ Htimes, the value of the cards reach Alice's favorite number, 42. More 4 X+ h0 U( o  Q% K: R3 b7 C0 S; k
precisely, find operations such that ((((val1 op1 val2) op2 val3) op3 val4)
! u$ ~1 _0 F) Eop4 val5) = 42.
) ^/ P; H2 c/ M0 HHelp Bob by writing a program to determine whether it is possible to reach
: Y; j8 \2 X# c4 k) i9 N7 s% z42 given 5 card values.
1 s  T  G' o9 U( I# E
; o* t. A7 g/ b0 _3 D. {For example, Bob picks 5 cards out of the deck containing 60, 1, 3, 5, and
' y4 m, [5 S& E) Y( g, X+ N20. Bob rearranges the cards and supplies four operations, so that 5 * 20 -
# L& \4 s+ ^2 L6 A4 t60 + 3 - 1 = 42.
" n" l. M  M" O! b0 IInput:
0 @3 o+ n, X9 t% [$ aThe input consists of five integers on a line, separated by spaces. Each 4 r6 U9 S& {; d5 u% F1 ]
integer V is 0 <= V <= 52.# j. y; m: u9 ^' o/ ~( u7 g" v
Output:
. T$ g1 L; M7 f) r* oPrint a line containing "YES" if it is possible to reach the value 42 2 B' q: Y1 G& ^5 H, g
according to the rules of the game, or "NO" otherwise.1 e, ~. l8 |9 K3 i5 S2 K
发表于 4-13-2015 12:38 PM | 显示全部楼层
枚举量不大吧  5! * 3 ^ 4 = 120 * 81 < 12000 全都枚举出来

27

主题

4

精华

288

积分

高级会员

Rank: 3Rank: 3

积分
288
 楼主| 发表于 4-13-2015 05:33 PM | 显示全部楼层
cpcs 发表于 4-13-2015 12:38 PM
. f; [# q5 S" S枚举量不大吧  5! * 3 ^ 4 = 120 * 81 < 12000 全都枚举出来

2 y, X5 p8 U6 {5 @# J+ ~恩, 但不是有5! * 4^4种可能吗?
& M0 T5 p' |( b) ?因为有4个operators: +, - , *, /
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表