#P13396. [GCJ 2010 #1C] Rope Intranet

[GCJ 2010 #1C] Rope Intranet

题目描述

A company is located in two very tall buildings. The company intranet connecting the buildings consists of many wires, each connecting a window on the first building to a window on the second building.

You are looking at those buildings from the side, so that one of the buildings is to the left and one is to the right. The windows on the left building are seen as points on its right wall, and the windows on the right building are seen as points on its left wall. Wires are straight segments connecting a window on the left building to a window on the right building.

You've noticed that no two wires share an endpoint (in other words, there's at most one wire going out of each window). However, from your viewpoint, some of the wires intersect midway. You've also noticed that exactly two wires meet at each intersection point.

On the above picture, the intersection points are the black circles, while the windows are the white circles.

How many intersection points do you see?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each case begins with a line containing an integer NN, denoting the number of wires you see.

The next NN lines each describe one wire with two integers AiA_i and BiB_i. These describe the windows that this wire connects: AiA_i is the height of the window on the left building, and BiB_i is the height of the window on the right building.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 1) and yy is the number of intersection points you see.

2
3
1 10
5 5
7 7
2
1 1
2 2
Case #1: 2
Case #2: 0

提示

Limits

  • 1T15.1 \leqslant T \leqslant 15.
  • 1Ai104.1 \leqslant A_i \leqslant 10^4.
  • 1Bi104.1 \leqslant B_i \leqslant 10^4.
  • Within each test case, all AiA_i are different.
  • Within each test case, all BiB_i are different.
  • No three wires intersect at the same point.

Small dataset (9 Pts, Test set 1 - Visible)

  • 1N2.1 \leqslant N \leqslant 2.

Large dataset (13 Pts, Test set 2 - Hidden)

  • 1N1000.1 \leqslant N \leqslant 1000.