HDU 6300 Triangle Partition

本文介绍了一个简单的算法,用于解决如何划分3*n个不共线点为不相交三角形的问题。该算法通过先对所有点进行排序,然后按顺序划分成三角形来实现。文章还提供了完整的C++代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【题目链接】
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值