题目描述
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
暴力
/*
USER_ID: test#birdstorm
PROBLEM: 85
SUBMISSION_TIME: 2014-03-05 21:08:58
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define For(i,m,n) for(i=m;i<n;i++)
#define MAXN 105
main()
{
int t, i, j, k, m, n, flag;
double a[MAXN], b[MAXN];
scanf("%d",&t);
while(t--){
flag=0;
scanf("%d",&n);
scanf("%lf%lf%lf%lf",&a[0],&b[0],&a[1],&b[1]);
For(m,2,n){
scanf("%lf%lf",&a[m],&b[m]);
for(i=0;i<m-1&&!flag;i++) For(j,i+1,m)
if(fabs(a[i]*b[j]-a[j]*b[i]+a[j]*b[m]-a[m]*b[j]+a[m]*b[i]-a[i]*b[m])<=1e-6) flag=1;
}
puts(flag?"Yes":"No");
}
return 0;
}