HDU 6300 Triangle Partition

【题目链接】
http://acm.hdu.edu.cn/showproblem.php?pid=6300

题目意思

给3*n个点(不存在3点共线)问你怎么划三角形任意两三角形都不相交。

解题思路

题解给的是用凸包做,但是题目既然三点不共线那么直接排序从左到右划分就好了

代码部分


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <string>
#include <map>
#include <math.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3
const int mod = 1e9+7;
const int N = 3e3+7;
int n,m;
struct node
{
    int x,y,i;
}a[N];
bool cmp (node x,node y)
{
    return x.x<y.x;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int n;
        scanf("%d",&n);
        for (int i = 0; i < 3*n; i++)
        {
            scanf("%d %d",&a[i].x,&a[i].y);
            a[i].i = i+1;
        }
        sort(a,a+3*n,cmp);
        for (int i = 0; i < 3*n; i++)
        {
            if ((i+1)%3 != 0)
                printf("%d ",a[i].i);
            else printf("%d\n",a[i].i);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/pashuihou/article/details/81179493