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 2000000
typedef 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;
}