Triangle Partition HDU - 6300(题解)

Triangle Partition

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 (1≤n≤1000) – the number of triangle to construct.
Each of the next 3n lines contains two integers xi and yi (−109≤xi,yi≤109).
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 (1≤ai,bi,ci≤3n) 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

题目概述

三角形分区

问题描述

Chiaki有3n个点p1 p2…p3n。保证没有三点共线。

Chiaki想要构造n个不连续三角形每个顶点来自3n个点。

输入

有多个测试用例。第一行输入包含一个整数T,表示测试用例的数量。为每个测试用例:

第一行包含一个整数n(1≤n≤1000)——三角形构造的数量。

保证所有n的总和不超过10000。

输出

对于每个测试用例,输出n行包含三个整数ai,bi,ci(1≤ai,bi,ci≤3 n)每个表示点的第i个三角形的指标使用。如果有多个解,您可以输出其中任何一个。

样例输入

1

1

1 2

2 3

3 5

样例输出

1 2 3

总结:这个题,对友一把过了,没看题,补一下。

思路:给3n个点p1 p2…p3n。保证没有三点共线。要求构造三个不连续的三角形。只需要按第一行排序即可。然后按序找出三个点即可。

上代码:

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int T; int n;
struct MyStruct
{
	int x, y;
	int z;
}a[3010];
bool cmp(MyStruct a, MyStruct b)
{
	if (a.x = b.x)
		return a.y < b.y;
	else
	{
		return a.x < b.x;
	}
}
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i = 0; i < 3 * n; ++i)
		{
			scanf("%d%d", &a[i].x, &a[i].y);
			a[i].z = i + 1;
		}
		sort(a, a + 3 * n,cmp);
		for (int i = 0; i < n; i++)
		{
			printf("%d %d %d\n", a[3 * i].z, a[3 * i + 1].z, a[3 * i + 2].z);
		}
	}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/fighting_yifeng/article/details/81269753