QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 22

#5837. Rope Intranet

统计

Problem

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.

problem_5837_1.png

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?

Input

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

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

Output

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

Limits

Time limit: 30 2 seconds per test set.

Memory limit: 1GB.

1 ≤ T ≤ 15.

1 ≤ Ai ≤ 104.

1 ≤ Bi ≤ 104.

Within each test case, all Ai are different.

Within each test case, all Bi are different.

No three wires intersect at the same point.

Small dataset (Test set 1 - Visible; 9 Points)

1 ≤ N ≤ 2.

Large dataset (Test set 2 - Hidden; 13 Points)

1 ≤ N ≤ 1000.

Sample

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

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.