HDU6300

编程入门 行业动态 更新时间:2024-10-21 18:33:00

HDU6300

HDU6300

HDU6300-Triangle Partition

题目:
Chiaki has
3n
3n
points
p
1
,
p
2
,…,
p
3n
p1,p2,…,p3n
. It is guaranteed that no three points are collinear.
Chiaki would like to construct
n
n
disjoint triangles where each vertex comes from the
3n
3n
points.
Input
There are multiple test cases. The first line of input contains an integer
T
T
, indicating the number of test cases. For each test case:
The first line contains an integer
n
n
(
1≤n≤1000
1≤n≤1000
) – the number of triangle to construct.
Each of the next
3n
3n
lines contains two integers
x
i
xi
and
y
i
yi
(

10
9

x
i
,
y
i

10
9
−109≤xi,yi≤109
).
It is guaranteed that the sum of all
n
n
does not exceed
10000
10000
.
Output
For each test case, output
n
n
lines contain three integers
a
i
,
b
i
,
c
i
ai,bi,ci
(
1≤
a
i
,
b
i
,
c
i
≤3n
1≤ai,bi,ci≤3n
) each denoting the indices of points the
i
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

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define MAX 8000struct point
{int x;int y;int num;
};int main()
{int T,n,mina;struct point a[MAX];scanf("%d",&T);while(T--){scanf("%d",&n);for(int i = 0;i < 3 * n;i++){cin >> a[i].x >> a[i].y;a[i].num = i + 1;}for(int i = 0;i < 3 * n;i++){mina = i;for(int j = i + 1;j < 3 * n;j++){if(a[j].x < a[mina].x) mina = j;}swap(a[mina],a[i]);}for(int i = 0;i < 3 * n;){cout << a[i].num << " "<< a[i + 1].num << " " << a[i + 2].num << endl;i += 3;}}return 0;
}

题目要求给出3n个点,并且每三个点都不共线。每次要求输出n组三角形的点的索引(1组输出三个点的索引)。这道题的思路是先建立一个结构体,每个结构体都代表一个点,结构体中有点的横坐标,纵坐标,以及点的索引。因为题目要求输出的三角形之间不能重合,所以在这里我将这些点根据横坐标的从小到大进行排序。那么,每次输出的三角形都不会重合。在这里我使用的选择排序(当然了,后来发现sort的耗时更少,所以也可以用sort进行排序),随后进行输出就可以了。

更多推荐

HDU6300

本文发布于:2024-02-26 06:36:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1701626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!