思路:
算一下斜率,相等就ok了
解答:
package bupt;import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;/*
*@author:Totoro
*@createDate:2020年3月16日下午3:32:54
*/
public class ThreePointsOnALine{public static void main(String[] args){Scanner cin=new Scanner(System.in);int t;t=cin.nextInt();cin.nextLine();while(t--!=0){int N=cin.nextInt();double[][] map=new double[101][2];for(int i=0;i<N;++i)for(int j=0;j<2;++j)map[i][j]=cin.nextDouble();if(N<3){System.out.println("No");continue;}Set<Double> k=new HashSet<>();int flag=0;for(int i=0;i<N;++i){k.clear();for(int j=0;j<N;++j){if(j==i)continue;double kk;if(map[i][0]==map[j][0])kk=1;elsekk=(map[i][1]-map[j][1])/(map[i][0]-map[j][0]);if(k.isEmpty())k.add(kk);else{if(k.contains(kk)){flag=1;break;}elsek.add(kk);}}if(flag==1)break;}if(flag==1)System.out.println("Yes");elseSystem.out.println("No");}}}