java - Pigeonhole principle in Algorithm problems -


i reading editorial problem on codefoces still not able understand beacuse using pigeonhole principle , not getting how apply pigeonhole priniciple on problem

here's problem editorial:

in problem use septimal number system. important limitation. let's count how many digits showed on watch display , call cnt. if cnt more 7, answer 0 (because of pigeonhole principle). if cnt not greater 7, can bruteforces cases.

here' problem statement http://codeforces.com/contest/686/problem/c

robbers, attacked gerda's cab, successful in covering kingdom police. make goal of catching them harder, use own watches.

first, know kingdom police bad @ math, robbers use positional numeral system base 7. second, divide 1 day in n hours, , each hour in m minutes. personal watches of each robber divided in 2 parts: first of them has smallest possible number of places necessary display integer 0 n - 1, while second has smallest possible number of places necessary display integer 0 m - 1. finally, if value of hours or minutes can displayed using less number of places in base 7 watches have, required number of zeroes added @ beginning of notation.

note display number 0 section of watches required have @ least 1 place.

little robber wants know number of moments of time (particular values of hours , minutes), such digits displayed on watches distinct. calculate number.

the "pigeonhole principle" this: if try put more 7 pigeons 7 pigeonholes, 1 of holes has more 1 pigeon in it.

here, septimal digits pigeonholes , places in time representation pigeons. so, if can determine (quickly) given case more 7 places needed represent time, pigeonhole principle tells there can no representations having distinct digits, , can skip slow work of counting such representations brute-force , go on next case.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -