累计每个屋顶的往返航行时间和上下船时间,最后向上取整。
OJ: noi_openjudge
题目 ID: ch0105-19
难度:入门
标签:几何模拟python
日期: 2026-07-30 23:01
题意
救生船从原点往返各屋顶。航速为 50 米/分钟,每人上船 1 分钟、下船 0.5 分钟,求总分钟数向上取整。
思路
坐标 math.hypot(x, y)。往返航行耗时为 2 * distance / 50,每人上下船共 1.5 分钟。累计所有屋顶后用 math.ceil 向上取整。
代码
Python代码
python
import math
rooftop_count = int(input())
total_time = 0.0
for _ in range(rooftop_count):
x, y, people = map(float, input().split())
total_time += 2 * math.hypot(x, y) / 50 + people * 1.5
print(math.ceil(total_time))C++代码
cpp
#include <cstdio>
#include <cmath>
double get_time(double x,double y){
double len = sqrt(x*x+y*y);
return 2*len / 50;
}
double get_up_down_time(int num){
return num +num*0.5;
}
int main(){
int n;
scanf("%d",&n);
int i;
double t1,t2;
int t3;
double time1 = 0;
for (i=1;i<=n;i++){
scanf("%lf%lf%d",&t1,&t2,&t3);
time1 += get_time(t1,t2);
time1 += get_up_down_time(t3);
//printf("%lf\n",time1);
}
printf("%d\n",(int)ceil(time1));
return 0;
}复杂度
时间复杂度为
总结
多地点独立往返时,总时间等于逐地点时间之和;“精确到分钟”要求最后向上取整。