B2066题解

· · 题解

这道题比较简单,按照题目编写程序。

首先,大本营距离每个房顶的距离其实就是 \sqrt{x \times x + y \times y}

其次,这个 x 坐标和 y 坐标不一定是整数!否则只能得40分。

AC Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    double sum = 0;
    for (int i = 1; i <= n; i++){
        double x, y;//注意是 double 类型
        int p;
        scanf("%lf%lf%d", &x, &y, &p);
        double dis = sqrt(x * x + y * y);
        sum += dis / 50 + p + dis / 50 + p * 0.5;
        //船往返的时间总和
    }
    printf("%d\n", int(ceil(sum)));//向上取整函数
    return 0;
}