zoukankan      html  css  js  c++  java
  • G

    These will be floating point numbers;看这句话,就是说数据会是浮点型的,

    问题(一)数据定义成double类型就过了

    我当时以为定义成float类型就可以了,

    因为题上说是float point number,但是定义成float类型的却wrong answer,同学让我改成double类型的,我当时问她依据

    她说没有依据,你试试呗,我挺固执地继续从别的地方找错误,没有依据?不可能嘛!最后无奈试了一下果真改了类型就对了,

    得出一个教训,题上让用的floating point numbers时候,你可以用double类型的数据存储,用不上那么长最后不用后边多余的位数就是了嘛

    问题(二)小数点后面有精确到7位才过,8位就不过

    还发现一个问题,存储PI的double类型数据,我定义成3.1415926就对了,定义成3.14159265就错了,

    可能是后台测评的时候用的PI就是3.1415926,但是我觉得也可以从题中找,题中说是floating point numbers

    我想意思就是定义精度为7~8位的数据就可以了,因为float精度7~8位,

    ps:我想了下,这道题给出的数据精度7~8位但是算的时候必须定义成double类型的原因是S = PI * R^2;这样一来,

    数据就会扩大很多,如果仍然用float类型存,就会丢失精度

    Description



    Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion. 

    After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.) 

     

    Input

    The first line of input will be a positive integer indicating how many data sets will be included (N). 

    Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. These will be floating point numbers measured in miles. The Y coordinate will be non-negative. (0,0) will not be given. 
     

    Output

    For each data set, a single line of output should appear. This line should take the form of: 

    “Property N: This property will begin eroding in year Z.” 

    Where N is the data set (counting from 1), and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. Z must be an integer. 

    After the last data set, this should print out “END OF OUTPUT.” 

    Notes: 

    1. No property will appear exactly on the semicircle boundary: it will either be inside or outside. 

    2. This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines. 

    3. All locations are given in miles. 
     

    Sample Input

    2 1.0 1.0 25.0 0.0
     

    Sample Output

    Property 1: This property will begin eroding in year 1. Property 2: This property will begin eroding in year 20. END OF OUTPUT.
    代码:
    #include <stdio.h>
    int main()
    {
        int n, case_num = 1;
        double x, y;
        int t;
        scanf("%d", &n);
        while(n--)
        {
            scanf("%lf%lf", &x, &y);
            double S = 3.1415926*(x*x + y*y)/2.0;
            t = (S / 50.0) + 1;
            printf("Property %d: This property will begin eroding in year %d.
    ", case_num++, t);
        }
        printf("END OF OUTPUT.
    ");
        return 0;
    }
  • 相关阅读:
    视图容器组件使用
    组件的学习
    伸展树
    二叉搜索树
    二叉树
    笛卡尔树
    二叉堆
    vim配置
    使用vim-pathogen 进行插件管理
    C/C++中的变量和静态变量
  • 原文地址:https://www.cnblogs.com/rain-1/p/4941580.html
Copyright © 2011-2022 走看看