2261: Triangle (皮克定理)

ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K27751Standard
A lattice point is an ordered pair (x, y) where x and y are both integers. Given the coordinates of the vertices of a triangle (which happen to be lattice points), you are to count the number of lattice points which lie completely inside of the triangle (points on the edges or vertices of the triangle do not count).

Input

    The input test file will contain multiple test cases. Each input test case consists of six integers x1, y1, x2, y2, x3, and y3, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and -15000 ≤ x1, y1, x2, y2, x3, y3 ≤ 15000.

    The end-of-file is marked by a test case with x1 = y1 = x2 = y2 = x3 = y3 = 0 and should not be processed.

Output

    For each input case, the program should print the number of internal lattice points on a single line.

Sample Input

0 0 1 0 0 1
0 0 5 0 0 5
0 0 0 0 0 0

Sample Output

0
6
/*
匹克定理(s=i+b/2-1)和辗转相除的应用
*/
#include <cstdio>
#include <iostream>
#include <memory>
#include <cmath>
using namespace std;
struct point
{
    int x,y;
}p[5];
int area()
{
    int ans=0;
    for(int i=0 ; i<3 ; i++)
    {
        ans+=p[i].x*(p[(i+1)%3].y-p[(i+2)%3].y);
        //printf("%d ",ans);
    }
    return ans;
}
int gcd(int a,int b)
{
 return b==0?a:gcd(b,a%b);
}
int atline (point p1,point p2)
{
    int b=fabs(p1.x-p2.x) , a=fabs(p1.y-p2.y);
    return gcd(a,b);//返回边上点的个数加上一个端点
}
int main ()
{
    int i,n;
    while (1)
    {
        bool flag=1;
        for ( i=0 ; i<3 ; i++)
        scanf("%d%d",&p[i].x,&p[i].y);
        for ( i=0 ; i<3 ; i++)
         if ( p[i].x || p[i].y )flag=0;
        if(flag) break;
        int s=fabs(area())+2,side=0;
        //cout<<s<<"/n";
        for (i=0 ; i<3 ; i++)
        {
            side+=atline(p[i],p[(i+1)%3]);
        }
        int ans=(s-side)/2;
        printf("%d/n",ans);
    }
    return 0;
}
/*
0 0 1 0 0 1
0 0 5 0 0 5
5 5 5 0 0 5
0 0 0 0 0 0
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
open3d::geometry::TriangleMesh::CreateFromPointCloudAlphaShape 函数是Open3D库中用来根据给定的点云数据创建一个三角网格表达的函数。但当调用这个函数时如果失败,可能由以下几个原因导致: 1. 点云数据为空:函数需要至少存在一个点云数据才能创建三角网格,如果没有输入点云数据,函数将无法执行。 2. Alpha参数设置错误:这个函数需要一个Alpha参数来定义点云数据中点之间的连接程度。如果Alpha参数的值设置得过小,可能导致连接的面过少,从而无法成功创建三角网格。相反,如果Alpha参数的值设置得过大,可能导致连接的面过多,从而导致函数执行时间过长甚至内存溢出。 3. 输入的点云数据不适用于三角网格表示:这个函数是基于Alpha形状重建方法的,对于某些形状的点云数据可能无法成功创建三角网格。例如,如果点云数据中的点分布非常稀疏或是非常集中,都可能导致函数执行失败。 为了解决上述问题,我们可以检查点云数据是否为空、调整Alpha参数的值或者尝试其他适用于形状重建的方法,如Marching Cubes,Poisson Reconstruction等。此外,我们还可以对点云数据进行预处理,例如进行滤波、重采样等操作,以提高函数的成功率。最后,如果上述方法都无法解决问题,可能需要考虑点云数据本身的质量或者使用其他库或方法来处理点云数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值