Bee Movie | ||||||
| ||||||
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). | ||||||
Input | ||||||
Line 1: A single integer, N | ||||||
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. . . . . 6 . 8
The digits mark the collinear bee IDs: . . . . * . *
|
翻译半天其实就一句话:给出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]);
}
}
}