bupt|118. Three Points On A Line

柔情只为你懂 2023-05-22 08:45 132阅读 0赞

时间限制 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.
对于每个测试用例,如果有三个点位于同一行,则输出Yes,否则输出No。

输入样例

  1. 2
  2. 3
  3. 0.0 0.0
  4. 1.0 1.0
  5. 2.0 2.0
  6. 3
  7. 0.001 -2.000
  8. 3.333 4.444
  9. 1.010 2.528

输出样例

  1. Yes
  2. No
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. int main() {
  6. int t, n;
  7. float a[105];
  8. float b[105];
  9. while(scanf("%d", &t) != EOF) {
  10. while(t--) {
  11. int flag = 0;
  12. scanf("%d", &n);
  13. for(int i = 0; i < n; i++) {
  14. scanf("%f", &a[i]);
  15. scanf("%f", &b[i]);
  16. }
  17. for(int i = 0; i < n && !flag; i++) {
  18. for(int j = i + 1; j < n && !flag; j++) {
  19. for(int k = j + 1; k < n && !flag; k++) {
  20. if((b[k] - b[j]) / (a[k] - a[j]) == (b[j] - b[i]) / (a[j] - a[i])) {
  21. flag = 1;
  22. }
  23. }
  24. }
  25. }
  26. if(flag == 1) {
  27. printf("Yes\n");
  28. } else {
  29. printf("No\n");
  30. }
  31. }
  32. }
  33. return 0;
  34. }

发表评论

表情:
评论列表 (有 0 条评论,132人围观)

还没有评论,来说两句吧...

相关阅读