85. Three Points On A Line
时间限制 1000 ms 内存限制 65536 KB
题目描述
Given points on a 2D plane, judge whether there're three points that locate on the same line.
输入格式
The number of test cases T(1≤T≤10) appears in the first line of input.
Each test case begins with the number of points N(1≤N≤100). The following N lines describe the coordinates (xi,yi) of each point, in accuracy of at most 3 decimals. Coordinates are ranged in [−104,104].
输出格式
For each test case, output Yes
if there're three points located on the same line, otherwise output No
.
输入样例
2
3
0.0 0.0
1.0 1.0
2.0 2.0
3
0.001 -2.000
3.333 4.444
1.010 2.528
输出样例
Yes
No
#include<iostream>
using namespace std;
struct point{
float x;
float y;
point(float a,float b):x(a),y(b){ //构造函数
}
point(){
x=0.0;
y=0.0;
}
};
point pit[100];
int main(){
int T;
cin>>T;
while(T--){
/*for(int i=0;i<100;i++){
pit[i].x=0.0;
pit[i].y=0.0;
}*/
int N;
cin>>N;
for(int i=0;i<N;i++){
cin>>pit[i].x;
cin>>pit[i].y;
}
bool flag1=false,flag2=false;
for(int i=0;i<N-2;i++){
for(int j=i+1;j<N-1;j++){
for(int k=j+1;k<N;k++){
if((pit[k].y-pit[j].y)*(pit[j].x-pit[i].x)
==(pit[k].x-pit[j].x)*(pit[j].y-pit[i].y)){
cout<<"Yes"<<endl;
flag1=true;
flag2=true;
break;
}
}
if(flag1)break;
}
if(flag2)break;
}
if(!flag1) cout<<"No"<<endl;
}
return 0;
}