UESTC 802 E - Just a Line
2016-06-01 22:38
267 查看
Description
There are N points on a plane, among them N−1 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. (4≤N≤50000)
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. (−109≤xi,yi≤109)
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)
代码:
There are N points on a plane, among them N−1 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. (4≤N≤50000)
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. (−109≤xi,yi≤109)
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; }
相关文章推荐
- 传到后台出现乱码request.getParameter()取值乱码问题
- UVALive 7035 Built with Qinghuai and Ari Factor(水题)
- require.js的简单使用
- UI更新的方法和在非UI线程里面,怎么更新UI信息。细细的
- Android编译时出现aapt.exe finished with non-zero exit value 1错误的解决方法
- 【解决】关于sscom不能保存当前窗口到文本文件的问题
- building workspace has encountered
- stl容器区别: vector list deque set map及底层实现
- UITableView的分割线长短的控制
- CodeForces 587E Duff as a Queen (线段树+线性基)
- jQueery-基础选择器
- 接口调用,输出结果为Json格式(ConvertTo-Json),提交参数给URL(WebRequest)
- 修改 Semantic UI 的默认字体
- Android Activity runonUiThread
- Poj2749 Building Roads
- UI进阶 FMDB
- 实在没想到系列——HashMap实现底层细节之keySet,values,entrySet的一个底层实现细节
- iOS——UICollectionView
- <GPS> Learning Neural Network Policies with Guided Policy Search under Unknown Dynamics
- UI(base)--android