hrbust 1069 哈理工oj Bee Movie【计算几何】【学习叉乘】

Bee Movie
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 64(47 users)Total Accepted: 54(45 users)Rating: Special Judge: No
Description

Barry B. Benson is "just an ordinary bee" in a hive located in Sheep's Meadow in Central Park in New York City. Barry recently graduated from college and is about to enter the hive's Honex Industries (a division of Honesco Corporation and owned by the Hexagon Group) honey-making workforce. Along with his best friend Adam Flayman (voiced by Matthew Broderick) Barry is initially very excited, but his latent, non-conformist attitude emerges upon finding out that his choice of job will never change once picked.He absolutely disappointed, he joins the team responsible for bringing the honey and pollination of the flowers to visit the world outside the hive. The bee will draw out in battle array when they want to go outside.

Actually, this problem is about alignment of N (1 ≤ N ≤ 455) bees numbered 1..N who are grazing in their field that is about 15,000×15,000 units. Their grazing locations all fall on integer coordinates in a standard x,y scheme (coordinates are in the range 0..15,000). 
       Barry looks up and notices that she is exactly lined up with Huacm534(bee) and AcmIcpc20060820322(bee). He wonders how many groups of three aligned bees exist within the field. 
       Given the locations of all the bees (no two bees occupy the same location), figure out all sets of three bees are exactly collinear. Keep track of the sets, sorting the bees in each set by their ID number, lowest first. Then sort the sets by the three ID numbers (lowest first), breaking ties by examining the second and third ID numbers.

Input

Line 1: A single integer, N 

Lines 2..N+1: Line i+1 describes bee i's location with two space-separated integers that are his x and y coordinates

Output

Line 1: A single integer X that is the number of sets of three bees that are exactly collinear. A set of four collinear bees would, of course, result in four sets of three collinear bees. 

 

Lines 2..X+1: Each line contains three space-separated integers that are the bee ID numbers of three collinear bees. The lines are sorted as specified above. This output section is empty if no collinear sets exist.

Sample Input
8
0 0
0 4
1 2
2 4
4 3
4 5
5 1
6 5
4
0 0
1 1
2 2
3 3
Sample Output
1
1 3 4
4
1 2 3
1 2 4
1 3 4
2 3 4
Hint

Be careful of floating point arithmetic. Floating point comparison for equality almost never works as well as one would hope. 

Explanation of the sample 1: 

Eight bees grazing on a grid whose lower left corner looks like this: 

. . . . 6 . 8  


2 . 4 . . . .  


. . . . 5 . .  


. 3 . . . . .  


. . . . . 7 . 


1 . . . . . .

 

The digits mark the collinear bee IDs: 

. . . . * . *  


* . 4 . . . .  


. . . . * . .  


. 3 . . . . .  


. . . . . * . 


1 . . . . . .


翻译半天其实就一句话:给出n个点,判断有哪三个点在一条直线上,如果在一条直线上输出他的位子。

AC代码:

 #include<stdio.h>
#include<string.h>
using namespace std;
struct Point
{
    int x,y;
}p[1000];
int ans[10000][3];
int cont;
int  chacheng(Point p1, Point p2, Point p3)
{
    return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        cont=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i;j<n;j++)
            {
                if(i==j)continue;
                for(int k=j;k<n;k++)
                {
                    if(i==k)continue;
                    if(j==k)continue;
                    int b=chacheng(p[i],p[j],p[k]);
                    if(b==0)
                    {
                        ans[cont][0]=i+1;
                        ans[cont][1]=j+1;
                        ans[cont][2]=k+1;
                        cont++;
                    }
                }
            }
        }
        printf("%d\n",cont);
        for(int i=0;i<cont;i++)
        {
            printf("%d %d %d\n",ans[i][0],ans[i][1],ans[i][2]);
        }
    }
}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值