아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Birthday Cake

시간 제한10초메모리 제한1024 MB

요약
주어진 직사각형의 모든 셀을 나머지 격자와 분리하는 데 필요한, 길이가 K 이하인 유효한 직선 절단의 최소 횟수를 구한다.
난이도

보통10점 중 7점

유형
기하, 그리디, 수학
정답자
아직 제출이 없습니다

문제

You are given a grid of R rows and C columns that corresponds to a birthday cake.

The rows are numbered from 1 to R starting from the top. The columns are numbered from 1 to C starting from the left. Each cell in the grid is a square of size 1×1.

You noticed that the most delicious part of the cake forms a single filled rectangle; that means all the cells inside this single rectangle will be delicious as well, but all the cells outside this rectangle are not delicious.

You have a knife that is long enough to make straight-line cuts of length up to K.

We want to make a series of cuts to extract each of the delicious cells separately, so that we can put candles on them, and enjoy the birthday party.

To extract each of the delicious cells separately, they must be disconnected from any other cell.

A cell is disconnected if no other cell is connected to it in any of the 4 directions (up, down, left, right).

A cut is a directed line segment which is valid if the following conditions are met:

  • The cut runs along one of the horizontal or vertical lines between the rows and columns of the grid.
  • The length of the cut must not exceed K.
  • The starting and ending points of the cut must be grid points (i.e. a corner of a cell). In addition, the starting point must be already exposed, meaning that it lies on one of the 4 sides of the grid or on one of the previous cuts.
  • The cut must not pass through any other exposed points. It may touch an exposed point, but if it does, it must end right there.

Suppose that K=4. Below you can find five examples of valid cuts.

And here are four examples of invalid cuts

  • In the first picture, the cut is too long (longer than 4).
  • In the second picture, the cut starts from an unexposed point (neither one of the 4 sides of the grid nor a previous cut).
  • In the third picture, the cut passes through an exposed point, it must stop once it touches the exposed point at length 2.
  • The fourth picture is invalid because of the same reason as the third picture.

We need to find the minimum number of cuts needed to extract all the delicious cells.

입력

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case starts with a line containing three integers, R, C and K.

The next line contains four integers, r1, c1, r2, c2, representing the top-left and bottom-right cell of the delicious rectangle respectively.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum number of cuts.

제한

  • 1 ≤ T ≤ 100.
  • 1 ≤ r1 ≤ r2 ≤ R.
  • 1 ≤ c1 ≤ c2 ≤ C.

힌트

In the Sample 1, the minimum number of cuts is 5. One of the possible series of cuts is as follows:

In the Sample 2, the minimum number of cuts is 3. One of the possible series of cuts is as follows:

예제2

  1. 예제 1

    입력
    1
    3 3 1
    2 2 2 2
    
    예상 출력
    Case #1: 5
    
  2. 예제 2

    입력
    1
    2 3 4
    2 1 2 2
    
    예상 출력
    Case #1: 3