Combination Lock
의견: 0
Farmer John's cows keep escaping, so he purchases a fancy combination lock to keep his cows from opening the pasture gate.
The lock has three dials, each numbered 1..N (1 <= N <= 100), where 1 and N are adjacent since the dials are circular. There are two combinations that open the lock, one set by Farmer John, and also a "master" combination set by the lock maker. The lock has a small tolerance for error, however, so it will open even if the numbers on the dials are each within at most 2 positions of a valid combination. For example, if Farmer John's combination is (1,2,3) and the master combination is (4,5,6), the lock will open if its dials are set to (1,N,5) (close enough to Farmer John's combination) or to (2,4,8) (close enough to the master combination). Note that (1,5,6) would not open the lock, since it is not close enough to any one single combination.
Given Farmer John's combination and the master combination, please determine the number of distinct settings for the dials that will open the lock. Order matters, so the setting (1,2,3) is distinct from (3,2,1).
Line 1: The integer N.
Line 2: Three space-separated integers, specifying Farmer John's combination.
Line 3: Three space-separated integers, specifying the master combination (possibly the same as Farmer John's combination).
The number of distinct dial settings that will open the lock.
combo.incombo.out50
1 2 3
5 6 7249Input details: Each dial is numbered 1..50. FJ's combination is (1,2,3); the master combination is (5,6,7).
riseoj 작성
출처 올림피아드 > USACO > 2013-2014 > November > Bronze
평가 및 의견
Combination Lock
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Combination Lock