ceil()函数的应用-hdu1065

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1065

题目描述:

floor(x)  is the largest integer not greater than x , 也就是,floor(x) 返回的是小于等于x的所有整数中最大的整数,简单的说,就是去掉x的小数部分的整数

ceil(x)  is the smallest integer not less than x,也就是,ceil(x) 返回的是大于等于x的所有整数中最小的整数,简单的说,就是如果x是整数,则返回该数,如果x不是整数,则不管小数部分是多少,都进一位然后返回。

例如:

floor(3.2)= 3;

ceil(3.2)= 4;

floor(4)= 4;

ceil(4)= 4;

代码实现:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#define PI 3.1415926;

using namespace std;
int main()
{
    double x,y;
    int T;scanf("%d",&T);
    for(int i=1;i<=T;i++){
        scanf("%lf%lf",&x,&y);
        double square=(x*x+y*y)*PI;//房子所在下标所围成的圆的面积(x*x+y*y)为R^2
        double year;
        year=ceil(square/2/50);//房子所在地是处在半圆中,所以square得除以2,每年的淹没速度为50平方米,所以再除以速度向上取整得出最终结果
        printf("Property %d: This property will begin eroding in year %d.\n",i,(int)year);
    }
    printf("END OF OUTPUT.\n");
    return 0;
}

 

posted @ 2018-11-30 20:57  里昂静  阅读(247)  评论(0编辑  收藏  举报