2018ACM暑假多校联合训练1003-Triangle Partition

题意是给3n个点,其中不可能存在任意三点共线的情况,让你在其中建n个三角形,点不能重复使用,三角形不能相互覆盖

做法是给每个点排序,按照先y轴排,再x轴排的顺序,三个三个一组从下往上输出,有人说是凸包,其实没那么麻烦

Problem Description

Chiaki has  3n points p1,p2,,p3n. It is guaranteed that no three points are collinear.
Chiaki would like to construct n disjoint triangles where each vertex comes from the 3n points.
 
Input
There are multiple test cases. The first line of input contains an integer  T, indicating the number of test cases. For each test case:
The first line contains an integer n (1n1000) -- the number of triangle to construct.
Each of the next 3n lines contains two integers xi and yi (109xi,yi109).
It is guaranteed that the sum of all n does not exceed 10000.
 
Output
For each test case, output  n lines contain three integers ai,bi,ci (1ai,bi,ci3n) each denoting the indices of points the i-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
 
 1 #include <cstdio>
 2 #include <algorithm>
 3 
 4 using namespace std;
 5 
 6 struct node
 7 {
 8     int n;
 9     int x, y;
10 }p[4010];
11 bool cmp(node a, node b)
12 {
13     if (a.y == b.y)
14         return a.x > b.x;
15     return a.y < b.y;
16 }
17 
18 int main()
19 {
20     int t, n;
21     scanf("%d", &t);
22     while (t--)
23     {
24         int n;
25         scanf("%d", &n);
26         for (int i = 0; i < 3 * n; i++)
27         {
28             scanf("%d %d", &p[i].x, &p[i].y);
29             p[i].n = i + 1;
30         }
31 
32         sort(p, p + (3 * n), cmp);
33         for (int i = 1; i <= 3 * n; i++)
34         {
35             printf("%d", p[i - 1].n);
36             if (i % 3 == 0)
37                 printf("\n");
38             else
39                 printf(" ");
40         }
41 
42     }
43 
44     
45     return 0;
46 }

猜你喜欢

转载自www.cnblogs.com/qq965921539/p/9356729.html