UESTC 802 E - Just a Line

Description
There are N points on a plane, among them N1 points will form a line, your task is to find the point that is not on the line.

Input
The first line contains a single number N , the number of points. (4N50000)

Then come N lines each with two numbers (xi,yi), giving the position of the points. The points are given in integers. No two points’ positions are the same. (109xi,yi109)

Output
Output the position of the point that is not on the line.

Sample Input
5
0 0
1 1
3 4
2 2
4 4

Sample Output
3 4

题意:找出那个不在直线上的点。先算出斜率,再遍历一次。
(排序那一段没用的gg)

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
typedef struct 
{
    int x;int y;
}Node;
int Sort(const void * a,const void * b)
{
    Node *p1=(Node *)a;
    Node *p2=(Node *)b;
    return p1->x>p2->x;
}
int main (void)
{
    Node point[100000];
    int t ;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        scanf("%d %d",&point[i].x,&point[i].y);
    //  printf("%d %d\n",point[i].x,point[i].y);
    }

    qsort(point,t,sizeof(Node),Sort);
//  printf("after\n");
//  for(int i=0;i<t;i++)
//  {
//      printf("%d %d\n",point[i].x,point[i].y);
//  }

//  printf("-------------\n");
    int ans1,ans2;
    int tmp1,tmp2;
    for(int k=0;k<=3;k++)
    {
        for(int j=0;j<k;j++)
        {
            for(int i=0;i<j;i++)
            {
                if((point[j].y-point[i].y)*(point[k].x-point[i].x)==(point[k].y-point[i].y)*(point[j].x-point[i].x))
                {
                    ans1=point[k].x-point[i].x;
                    ans2=point[k].y-point[i].y;
                    tmp1=point[i].x;
                    tmp2=point[i].y;
                    break;
                }   
            }
        }
    }

    for(int i=0;i<t;i++)
    {
        if((point[i].y-tmp2)*ans1!=ans2*(point[i].x-tmp1))

        {
            printf("%d %d\n",point[i].x,point[i].y);
            break;
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值