QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#17777. 星圖重繪

Statistics

題目背景

隨著流光解密挑戰的圓滿完成,全息光樹被完全點亮,盛大的十週年慶典也悄然步入尾聲。作為慶典的最後環節,小 T 和小 S 邀請大家來到了一塊描繪著漫天星圖的數字畫板前。

歲月流轉,過往繪就的星座連線已隨著時間悄然淡化,此時的畫板又回到了僅有孤立星辰散布的模樣。小 S 遞給現場的大家特制的星圖筆,希望大家能重新補全這份星圖。為了使重繪的紀念星圖呈現出極致的美感,連結星辰時必須保持結構的平衡。

伴隨著悠揚的旋律,大家紛紛上前,希望能在這片星海中點亮尽可能多的星座,為這場十週年紀念晚會留下最璀璨的收官之作。

畫板上共有 $n$ 顆星辰,可將其視為二維平面上的點。第 $i$ ($1 \le i \le n$) 顆星辰的座標為 $(x_i, y_i)$。已知所有星辰的橫座標兩兩不同,縱座標也兩兩不同。

每次繪製星座時,你需要從這 $n$ 顆星辰中選取三顆,將它們兩兩連接構成一個三角形。為了體現平衡的美感,該三角形必須滿足特定的邊界要求:存在一個四條邊均平行於座標軸的矩形,使得該三角形的三個頂點恰好都落在這個矩形的邊界上。同時,為了維持星圖的清晰結構,所有連結出的三角形的內部區域(不包含頂點與邊界)必須兩兩互不相交。

請你計算出最多能成功繪製多少個星座,並給出一組具體的繪製方案。

輸入格式

每個測試點中包含多組測試數據。輸入的第一行包含一個正整數 $T$ ($1 \le T \le 2 \times 10^4$),表示數據組數。對於每組測試數據:

  • 第一行包含一個正整數 $n$ ($3 \le n \le 2 \times 10^5$),表示星辰的數量。
  • 接下來 $n$ 行,第 $i$ ($1 \le i \le n$) 行包含兩個整數 $x_i, y_i$ ($|x_i|, |y_i| \le 10^9$),表示第 $i$ 顆星辰的座標。保證所有 $x_i$ 兩兩不同,所有 $y_i$ 兩兩不同。

保證所有測試數據中 $n$ 的和不超過 $2 \times 10^5$。

輸出格式

對於每組測試數據:

  • 第一行輸出一個非負整數 $m$,表示最多能繪製的星座數量。
  • 接下來 $m$ 行,每行輸出三個不同的正整數 $x, y, z$ ($1 \le x, y, z \le n$),表示構成一個星座的三顆星辰。

範例

輸入格式 1

2
8
-10 1
-2 6
5 10
8 -9
-1 -2
3 0
0 3
1 -8
8
8 8
-5 3
-4 1
5 7
10 10
-3 5
-8 -10
-7 -1

輸出格式 1

8
6 5 8
6 8 4
1 6 5
7 1 6
2 7 1
3 2 7
3 7 6
3 6 4
2
2 3 8
6 2 3

說明

對於第一組測試數據,範例輸出中繪製的星圖如下圖所示:

對於第二組測試數據,範例輸出中繪製的星圖如下圖所示:

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1608EditorialOpenNew Editorial for Problem #17777Anonymous2026-05-29 19:29:54View
#1598EditorialOpenOfficial EditorialAnonymous2026-04-28 21:49:17View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.