[分享] Google codejam 2017 程式设计比赛题目 3 of 4

这题我对了 Small dataset1,dataset2, Large dataset 答错了

ProblemA certain bathroom has N + 2 stalls in a single row; the stalls on the left and right ends are permanently occupied by the bathroom guards. The other N stalls are for users.Whenever someone enters the bathroom, they try to choose a stall that is as far from other people as possible. To avoid confusion, they follow deterministic rules: For each empty stall S, they compute two values LS and RS, each of which is the number of empty stalls between S and the closest occupied stall to the left or right, respectively. Then they consider the set of stalls with the farthest closest neighbor, that is, those S for which min(LS, RS) is maximal. If there is only one such stall, they choose it; otherwise, they choose the one among those where max(LS, RS) is maximal. If there are still multiple tied stalls, they choose the leftmost stall among those.K people are about to enter the bathroom; each one will choose their stall before the next arrives. Nobody will ever leave.When the last person chooses their stall S, what will be the values of max(LS, RS) and min(LS, RS) be?Solving this problemThis problem has 2 Small datasets and 1 Large dataset. You must solve the first Small dataset before you can attempt the second Small dataset. You will be able to retry either of the Small datasets (with a time penalty). You will be able to make a single attempt at the Large, as usual, only after solving both Small datasets.InputThe first line of the input gives the number of test cases, T. T lines follow. Each line describes a test case with two integers N and K, as described above.OutputFor each test case, output one line containing Case #x: y z, where x is the test case number (starting from 1), y is max(LS, RS), and z is min(LS, RS) as calculated by the last person to enter the bathroom for their chosen stall S.Limits1 ≤ T ≤ 100.1 ≤ K ≤ N.Small dataset 11 ≤ N ≤ 1000.Small dataset 21 ≤ N ≤ 106.Large dataset1 ≤ N ≤ 1018.SampleInput        Output5            Case #1: 1 04 2          Case #2: 1 05 2          Case #3: 1 16 2          Case #4: 0 01000 1000    Case #5: 500 4991000 1In Case #1, the first person occupies the leftmost of the middle two stalls, leaving the following configuration (O stands for an occupied stall and . for an empty one): O.O..O. Then, the second and last person occupies the stall immediately to the right, leaving 1 empty stall on one side and none on the other.In Case #2, the first person occupies the middle stall, getting to O..O..O. Then, the second and last person occupies the leftmost stall.In Case #3, the first person occupies the leftmost of the two middle stalls, leaving O..O...O. The second person then occupies the middle of the three consecutive empty stalls.In Case #4, every stall is occupied at the end, no matter what the stall choices are.In Case #5, the first and only person chooses the leftmost middle stall.

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章