For each grid size S and one of four chess piece moves, find the chromatic number of the S by S grid graph induced by that move's conflict rule.
Medium7GraphMathCombinatoricsImplementationNo attempts yetTime limit2sMemory limit512 MBThe committee preparing the anniversary of an amusement park invited a well known dance company to put on the celebration performances. The company prepared four group dances on a chess theme, called the king performance, the knight performance, the bishop performance and the rook performance.
Several teams of dancers appear in each dance. The chief choreographer holds that a dancer who sees a teammate during a performance is likely to copy that teammate's movements by mistake. Dancers of the same team therefore have to be spread over the stage so that dancers of other teams hide them. The four performances differ so much in movement and mood that one arrangement cannot be reused across them.
The committee turned the company's demands into the following conditions, one set per performance.
A performance takes place on a square S×S grid of markers on the floor. One dancer occupies one marker, no marker is left empty, and no two dancers share a marker. Each dancer stays on the same marker for the whole performance and belongs to exactly one team.
The center of every marker lies on an integer lattice point of a Cartesian grid, and the distance between the centers of two closest markers is 1. Take two different markers A and B whose centers are at (x1,y1) and (x2,y2).
For each of the four dances, find the minimum number of teams needed to perform it.
The input holds several test cases and continues until the end of the file. Each line contains an integer S (1≤S≤1000), one space, and one of the capital letters K, N, B, R. S is the size of the marker grid, and the four letters denote the king performance, the knight performance, the bishop performance and the rook performance.
For each test case, print on its own line the minimum number of teams needed to perform the given dance on a marker grid of the given size.