|
亲!马上注册或者登录会查看更多内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 Sophia 于 11-5-2015 02:07 AM 编辑 0 c6 q& N. v7 K
' \. w% e5 x- }6 J
// This is the text editor interface.
: F$ n8 ?9 A% X+ d// Anything you type or change here will be seen by the other person in real time. m2 L6 p. _- L
& K8 ?3 ~% Y% k( Z+ p$ m' w
/*8 R B8 Q# z. _* v* U( i; e1 P
Consider a grid where all the points are represented by integers.
2 ?! }- {( T) Z; b0 H) V
" a8 ?7 w3 E. A5 k. X& M.........................................
- ^2 j7 S6 Q- D...(-2,2) (-1,2) (0,2) (1,2) (2,2)...
- |2 A: F; E+ {9 T$ s- q) o...(-2,1) (-1,1) (0,1) (1,1) (2,1)....3 X$ E- L: H, N0 r. l' O, j
...(-2,0) (-1,0) (0,0) (1,0) (2,0)...6 a: x- T+ Y, `1 D" {( F
...(-2,-1) (-1,-1) (0,-1) (1,-1) (2,-1).... - z; a5 v, y6 W5 W
...(-2,-2) (-1,-2) (0,-2) (1,-2) (2,-2)...
( w% _9 a/ I2 o- x..........................................
& \% U) k$ C3 M1 u
: p2 m) d+ a8 y# W/ ^& @- sk-Snap point: A point whose digits sum up to less than or equal to k. In this
2 c; b$ a" R5 d5 v8 V* Equestion, we ignore all the signs in the number. For exxample, (1, 0) is a 1-snap point, (0, 10) is a 1-snap point, and (-100, 0) is also a 1-snap point; however (11, 0) is not a 1-snap point.
7 J* t& L {) z) [, i6 W; i! n$ H/ |# D& Z5 D, B7 p M. q' {& s
Question 1: Implement the following function# ]& `' S$ g1 T* ^8 X) |
boolean isSnapPoint(Point p, int k)
: n- g# j+ _- F- {& G, _. m) U) m0 o* o
Returns true if p is a k-snap point, and false otherwise..1point3acres缃�3 x% H0 k8 y( G& F
9 \* `* q# ?3 g8 @, M% p: y5 k% KReachable k-snap point: A k-snap point is a reachable k-snap point if there is a path from (0,0) to that point, where the path only consists of k-snap points.
1 f3 S$ T) J/ p' j, P( q
! G, K, J- N% IQuestion 2: Given k, return all the reachable k-snap points.
/ u; A( ?& A" Y3 n0 [; p*/# n9 d+ n2 C. E2 X A
|
|