optimal algorithm strategy for a 2 player game -


this question came across in 1 of online coding contests:

this 2 player game . there 2 breeds of warriors start off "a" , "b". given n cities , each city i has w[i] number of warriors (which can either of breed or b) . each warrior j in city has strength s[j] .

the first player has choose breed of warrior . second player gets other breed .in turn , player must choose city , warrior in city of choosen breed.

one player choose breed of warrior , city start game . warrior kill every other warrior of city less strength him irrespective of breed. @ end die. next , second player choose city , breed , same. continues until there no more moves left.

the first player has decide breed of warrior choose wins or if there no way him win if opponent plays optimally.

what optimal algorithm strategy first player win.

example -

let there 1 city (c1) 2 warriors- w1 of strength 10 , breed a , w2 of strength 15 , breed b.

the first player chose breed b warrior kill other warrior , hence second player won't have warrior choose from.

from description optimal solution easy. each warrior in city pick highest power warrior. count top warriors each city , whatever breed has best warriors win.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -