当前位置: 代码迷 >> 综合 >> 2018杭电多校day1_C Triangle Partition HDU - 6300
  详细解决方案

2018杭电多校day1_C Triangle Partition HDU - 6300

热度:50   发布时间:2023-11-05 08:24:22.0

Chiaki has 3n3n points p1,p2,…,p3np1,p2,…,p3n. It is guaranteed that no three points are collinear. 
Chiaki would like to construct nn disjoint triangles where each vertex comes from the 3n3n points. 

Input

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case: 
The first line contains an integer nn (1≤n≤10001≤n≤1000) -- the number of triangle to construct. 
Each of the next 3n3n lines contains two integers xixi and yiyi (?109≤xi,yi≤109?109≤xi,yi≤109). 
It is guaranteed that the sum of all nn does not exceed 1000010000. 

Output

For each test case, output nn lines contain three integers ai,bi,ciai,bi,ci (1≤ai,bi,ci≤3n1≤ai,bi,ci≤3n) each denoting the indices of points the ii-th triangle use. If there are multiple solutions, you can output any of them. 

Sample Input

1
1
1 2
2 3
3 5

Sample Output

1 2 3

又是一道队友找到的签到题,当时我在做最后一个模拟时区题吧。队友连A两道还是满惭愧的.....

赛后补一下题吧。。。。

题意:给3n个点,任意三点之间不共线,让你将其连线成n个互相不相交的三角形。

思路:由于任意三点不共线,只要按照x轴从小到大排序,然后依次取三个点出来连线,这样取出来的必然是不共线的。

(在二维平面画图可知,在相同的竖线上不会超过两个点,依次连续的三个点连线不会有交线)

代码:

#include<bits/stdc++.h>#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;#define N 200
#define MAX 2000000typedef long long ll;struct Node{int x,y,id;
}node[3005];bool cmp(Node a,Node b){if(a.y==b.y) return a.x<b.x;return a.y<b.y;
}int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=0;i<3*n;i++){scanf("%d%d",&node[i].x,&node[i].y);node[i].id=i;}sort(node,node+3*n,cmp);int k=1;for(int i=0;i<3*n;i++){if(k==3){printf("%d\n",node[i].id+1);k=1;continue;}printf("%d ",node[i].id+1);k++;}}return 0;
}

 

  相关解决方案