HDU - 6300 Triangle Partition 贪心

题意:

给定3*n个点,构造n个三角形,要求任意两个三角形没有重叠,输出n个三角形的点的标号;

不存在三点共线

思路:

不存在三点共线的话,只要按照x坐标排序后,相邻的三个点一定跟后面点组成的三角形不重叠,

所以不用求凸包;

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
const int maxn = 3000 + 7;

struct node {
    int x, y, id;
}a[maxn];
bool cmp(node a, node b) {
    return a.x < b.x;
}

int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        int n; scanf("%d", &n);
        //id = 1;
        int m = 3*n;
        for(int i = 1; i <= m; ++i) {
            int x,y;
            scanf("%d%d", &x,&y);
            a[i].x = x; a[i].y = y; a[i].id = i;
        }
        sort(a+1,a+1+m, cmp);
        for(int i = 1; i <= m; i += 3) {
            printf("%d %d %d\n", a[i].id, a[i+1].id, a[i+2].id);
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/xiang_6/article/details/81188882