1003 Triangle Partition (2018 Multi-University Training Contest 1)

Triangle Partition

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 2140    Accepted Submission(s): 925
Special Judge


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
 
题意:给出点的坐标(保证三点不共线),由这些点构成不相交的三角形。
 
分析: 简单题,根据x轴排序,根据顺序输出就A了。画个图很容易理解。
 
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int t;
 5 int n;
 6 struct point {
 7     int num;
 8     int x;
 9     int y;
10 }p[3005];
11 
12 bool cmp(struct point p1, struct point p2) {
13     return p1.x<p2.x;
14 }
15 
16 int main()
17 {
18     scanf("%d",&t);
19     while(t--) {
20         scanf("%d",&n);
21         for(int i=0; i<3*n; ++i) {
22             scanf("%d%d",&p[i].x,&p[i].y);
23             p[i].num = i+1;
24         }
25         sort(p,p+3*n,cmp);
26         for(int i=0; i<3*n; i+=3) {
27             printf("%d %d %d\n",p[i].num,p[i+1].num,p[i+2].num);
28         }
29     }
30     
31     return 0;
32 }

 

posted @ 2018-07-29 21:40  抓不到我  阅读(68)  评论(0)    收藏  举报