#P13446. [GCJ 2009 #3] Football Team

[GCJ 2009 #3] Football Team

题目描述

A football team will be standing in rows to have a photograph taken. The location of each player will be given by two integers xx and yy, where yy gives the number of the row, and xx gives the distance of the player from the left edge of the row. The xx values will be all different.

In order to make the photo more interesting, you're going to make sure players who are near each other have shirts of different colors. To do this, you set the following rule:

For each player PP:

  • The closest player to the right of PP in the same row, if there is such a player, must have a different shirt color.
  • The closest player to the right of PP in the previous row, if there is such a player, must have a different shirt color.
  • The closest player to the right of PP in the next row, if there is such a player, must have a different shirt color.

More formally, if there is a player at (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), where x1<x2x_1 < x_2, then those two players must have different shirt colors if:

  • y11y2y1+1y_1 - 1 \leq y_2 \leq y_1 + 1, and
  • there is no x3x_3 such that there is a player at (x3,y2)(x_3, y_2) and x1<x3<x2x_1 < x_3 < x_2.

Find the minimum number of distinct shirt colors required so that this is possible.

输入格式

The first line of input contains a single integer TT, the number of test cases. Each test case starts with a line that contains an integer NN, the number of players, followed by NN lines of the form

xx yy

each specifying the position of one player.

输出格式

For each test case, output

Case #X: cc

where XX is the test case number, starting from 1, and cc is the minimum number of colors required.

3
3
10 10
8 15
12 7
5
1 1
2 1
3 1
4 1
5 1
3
1 1
2 2
3 1
Case #1: 1
Case #2: 2
Case #3: 3

提示

Limits

  • 1T1001 \leqslant T \leqslant 100
  • 1x10001 \leqslant x \leqslant 1000
  • The values of xx will all be different.

Small dataset(8 Pts)

  • 1y151 \leqslant y \leqslant 15
  • 1N1001 \leqslant N \leqslant 100

Large dataset(19 Pts)

  • 1y301 \leqslant y \leqslant 30
  • 1N10001 \leqslant N \leqslant 1000