您的位置:首页 > 其它

进阶项目7-紧急救援

2016-07-29 22:17 218 查看
任务和代码:救生船每次将从大本营出发,救了人之后将人送回大本营。已知救生船速度50米/分钟,逐个屋顶救人,每人上船1分钟,下船0.5分钟。以救援大本营为原点,输入每个屋顶的位置坐标和屋顶上的人数,求出所有人都到达大本营并登陆所用的时间。

/*
文件名:main.c
作者:小风景
完成日期:2016.7.29
问题描述:救生船每次将从大本营出发,救了人之后将人送回大本营。已知救生船速度50米/分钟,逐个屋顶救人,每人上船1分钟,下船0.5分钟。以救援大本营为原点,输入每个屋顶的位置坐标和屋顶上的人数,求出所有人都到达大本营并登陆所用的时间。
程序输出:
*/

#include <stdio.h>
#include <math.h>
#include <malloc.h>

typedef struct
{
float x;
float y;
int people;
}rescuepoint;

double rescuetime(rescuepoint *point);

int main()
{
int pointnumber = 0; //需要救援的地点数目
int i = 0;
double time = 0;

printf("请输入需要救援的地点数目:");
scanf("%d",&pointnumber);
rescuepoint a[pointnumber] = {0};
rescuepoint *p = NULL;
for(i = 0;i < pointnumber;i++)
{
printf("请输入第%d个需要救援地点的坐标(x,y)和人数:",i+1);
fflush(stdin); //清空上次的输入缓存,防止读入错误数据
scanf("%f %f %d",&a[i].x,&a[i].y,&a[i].people);
}

for(i = 0;i < pointnumber;i++)
{
p = &a[i];
time += rescuetime(p);
}

printf("所有人都到达大本营并登陆所用的时间是:%.2f /min",time);
return 0;
}

double rescuetime(rescuepoint *point)
{
double time = 0;

time += 2 * sqrt(point->x*point->x + point->y*point->y) / 50 + 1.5*point->people;

return time;
}


程序运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: