zoukankan      html  css  js  c++  java
  • BOJ 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(1T10) appears in the first line of input.

    Each test case begins with the number of points N(1N100). 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 <stdio.h> 
    #include <stdlib.h> 
    #include <math.h> 
    
    
    main() 
    { 
        int T, i, j, k, m, n, flag; 
        double a[100], b[100]; 
        scanf("%d",&T); 
        while(T--){ 
            flag=0; 
            scanf("%d",&n); //n numbers
            scanf("%lf%lf%lf%lf",&a[0],&b[0],&a[1],&b[1]); 
            for(m = 2; m <= n - 1; m++){
                
                scanf("%lf%lf",&a[m],&b[m]); 
                for(i=0;i<= m-2&&!flag;i++) 
                {
                    for(j = i+1; j <= m - 1;j++) 
                    {
                        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;
                    }
                }
    
            } 
            printf("%s
    ",flag?"Yes":"No");
            //puts(flag?"Yes":"No"); 
        }  
        return 0; 
    } 

    暴力突破:

    读取组数T

     while(T--)

    {

      读取第T组数点的个数N,和前两个点;

      标识量清零(flag);

      for( 2 <=m <= N-1,m++)

      {

        读取点m,a[m],b[m](x,y坐标);

          /*开始已有点搜索,每暴力搜索一遍,都可能会影响flag,即已有数是否有三点共线,故在这里判断flag*/

        for( i 从0到m-2)

        {

          for( j从1到m-1)

          { //判定公式     

            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;

          }

        }  

      }

      输出flag(Yes or No);

    }


    注意点: 
      逻辑层次
      puts 和printf
    ________你所记的,都是假的。
  • 相关阅读:
    net.sf.json.JSONObject maven下载到了但是java后台一直用不了问题
    创建springboot2.1项目运行报错
    百度地图,加载顺序异步问题,用定时器解决
    大话设计模式--(1)简单工厂模式
    H5页面单点登录跳回首页 http url参数转义
    H5页面,百度地图点击事件
    批量给数据两边加上双引号和逗号
    java基础源码 (6)--ArrayListt类
    前端 移动端H5页面 DEBUG
    H5页面,华为手机打开不加载JS的问题
  • 原文地址:https://www.cnblogs.com/pudding-ai/p/3676709.html
Copyright © 2011-2022 走看看