30 likes | 125 Views
Help Mr. Fruit decipher the code by comparing his guesses with the correct answer. Use brute force method to check all possibilities and determine if the guesses are accurate or not. Time complexity is reduced by considering repeated combinations.
E N D
11412: Dig the Holes • ★★☆☆☆ • 題組:Problem Set Archive with Online Judge • 題號:11412: Dig the Holes • 解題者:鄭凱原 • 解題日期:2008年9月2日 • 題意:猜數字遊戲英文版。答案由10個數字挑4個數字改為6個英文字挑4個字,Mr.Fruit 想知道兩次答案的回傳有沒有矛盾的地方。 測資第一個數字表示接下來有幾組測資,每組測資會有兩行,每行會有四個英文字和2個數字,英文表示Mr.Fruit猜測的答案,第一個數字表示猜測的答案中,有幾個字是正確答案之一且在正確位置的,第二個是數字表示有幾個字是正確答案之一但不在正確位置的。
題意範例: Sample Input 7 VRBG 2 2 // 第二行4 0表示正確答案即為RVGO RVGO 4 0 // 由此帶入第一行的答案 後面數字應該是0 3 因此這組測資的答案為Cheat YGOR 4 0 RGOB 4 0 RBVY 2 1 ORVY 4 0 Sample Output Cheat Cheat Possible
解法:暴力法 因為只有6個英文,所以答案只有720組(6!),因此,只需要把所有的答案跟兩筆測資作比對,若有任何一組答案符合測資的數字,代表Possible,否則,即為Cheat。 • 解法範例:無 • 討論: 時間複雜度:6!/2 = 360 720組答案中,有一半是重複的,可忽略不計。