UESTC 802 E - Just a Line

原创 2016年06月01日 22:38:09

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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

UESTC 802—— Just a Line

题意:给出n个点,其中有n-1个点在同一个直线上,请你找出那个不在同一条直线上的点 解题思路:已知最多有50000个点,可用枚举的方法进行。首先将n个点保存下来,然后从第一个点开始,依次比较它与前四个...

UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论

看清楚题目就好了 or if the user’s password length is at least 8 characters and the user made a mistake with...

2016 UESTC Training for Math Problem E- 蹲在墙角画圈圈的愚人王

E - 蹲在墙角画圈圈的愚人王 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/O...

The 9th UESTC Programming Contest Warmup 1 A B D E

出了4题,rank 37 A ,水题,看字符串里有多少个TTT, TTH, THT, THH, HTT, HTH, HHT and HHH 1A#include #include #inclu...

2014 UESTC Training for Data Structures—— E - 休生伤杜景死惊开

解题思路:树状数组。假设x[i]是数值为i的数的个数,所以求的比q[i]小的数就有x[i-1]+x[i-2]+…..+x[2]+x[1],于是就可以用树状数组来写了,从头到尾扫一遍,对每个数都算一下前...

UESTC Training for Data Structures——E

Problem  E Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total...

kuangbin——线段树专题 E - Just a Hook

E - Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub...

2016 UESTC Training for Search Algorithm & String E - 吴队长征婚 dfs剪枝、好题

好复杂的搜索剪枝(┬_┬) 看了原题的一些结题报告 1. 搜索顺序。首先依据小棒长度进行由大到小的排序,在每一层搜索时首先将长度大的小棒填入 当前原棒中。因为当相对长的小棒占...

2016 UESTC Training for Search Algorithm & String(A B C E I K)

A - Xiper的奇妙历险(1) 题意:给你一个数n(貌似只给了9。。。)让你输出n皇后的不冲突的方法总数,以及输出全部的解。 B - Xiper的奇妙历险(2) 迷宫问题 C - Xipe...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UESTC 802 E - Just a Line
举报原因:
原因补充:

(最多只允许输入30个字)