SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
30.
SRM 543 EllysXors
● Problem Statement
● XOR problems became very popular in
TopCoder recently. (If you do not know
the bitwise operation XOR, see the
Notes section for an explanation.)
That's why Elly decided to invent one
of her own. Fortunately for you, the
one she came up with is quite simple.
You are given two longs L and R. She
wants you to find the XOR of all
numbers between L and R, inclusive.
姫路 IT 系勉強会 Vol. 6 @kakkun61 30/82
31.
SRM 543 EllysXors
● 要点だけ日本語に訳すと、
● L と R を与えるから、
● L ⊕L+1 ⊕... ⊕R を求めよ
1 ≦ L, R ≦ 4,000,000,000
●
ただし、
L ≦R
●
●
姫路 IT 系勉強会 Vol. 6 @kakkun61 31/82
77.
深さ優先探索 Depth First Search
● 問題
● 整数 a1, a2, ... an が与えられます。そ
の中からいくつか選び、その和をちょう
ど k にすることができるかを判定しな
さい。
● ただし、
● 1 ≦ n ≦ 20
● -108 ≦ ai, k ≦ 108
姫路 IT 系勉強会 Vol. 6 @kakkun61 77/82
78.
深さ優先探索 Depth First Search
● 例えば
● n = 4
● a = {1, 2, 4, 7}
●
このとき状態を表す木は次のようになる
姫路 IT 系勉強会 Vol. 6 @kakkun61 78/82
79.
深さ優先探索 Depth First Search
i=0
a = {1, 2, 4, 7} sum = 0
+1
i=1 i=1
sum = 0 sum = 1
+2
i=2 i=1
sum = 0 sum = 2
+4
i=3 i=3
sum = 2 sum = 6
姫路 IT 系勉強会 Vol. 6 @kakkun61
+7 79/82
80.
深さ優先探索 Depth First Search
● コードで表すと
姫路 IT 系勉強会 Vol. 6 @kakkun61 80/82
81.
深さ優先探索 Depth First Search
姫路 IT 系勉強会 Vol. 6 @kakkun61 81/82