北邮复试机试: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.

#include<iostream>
#include <cstdio>
using namespace std;
const int NUM=101;
double ayy[NUM][2];

int main()
{
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		int count=0;
		int i;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%lf %lf",&ayy[i][0],&ayy[i][1]);
			if(i>1)
			{
				for(int j=1;j<i&&!count;j++)
				for(int k=0;k<j&&!count;k++)
				if((ayy[i][1]-ayy[j][1])/(ayy[i][0]-ayy[j][0])==(ayy[j][1]-ayy[k][1])/(ayy[j][0]-ayy[k][0]))
				{
				
					count=1;
					
				}
			}
		}
		
		if(!count)
		printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}
//注意输出要求
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值