北邮机试---85. Three Points On A Line

 

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值