2020 BIT冬训-C++STL D - Triangle Partition HDU - 6300

Problem Description
  Chiaki has 3n points p1,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 3n 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 (1n1000)

-- the number of triangle to construct.Each of the next 3n3n lines contains two integers xixi and 

yiyi (109xi,yi109).It is guaranteed that the sum of all nn does not exceed 10000.

 

Output

For each test case, output nn lines contain three integers ai,bi,ciai,bi,ci (1ai,bi,ci3n) 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

大意就是有3n个三点不共线的点(即任意3个点都可以构成三角形),需要构造出n个不相交的三角形。输出每个三角形构成的点是原输入的第几个点。
算是贪心的思路,排序完即可。
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct node{
    int x,y,id;
}node1[3005];
int cmp(node a,node b){
    if(a.x == b.x)
        return a.y<b.y;
    else
        return a.x<b.x;
}
int t,n;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        n *=3;
        for(int i=0;i<n;i++){
            scanf("%d%d",&node1[i].x,&node1[i].y);
            node1[i].id=i;
        }
        sort(node1,node1+n,cmp);
        for(int i=0;i<=n-3;i+=3)
            printf("%d %d %d\n",node1[i].id+1,node1[i+1].id+1,node1[i+2].id+1);
    }
    return 0;
}

 

posted @ 2021-02-02 16:10  mikku  阅读(58)  评论(0)    收藏  举报