飞机场调度

活动调度

题目

在本实验中,需要同学们利用队列实现一个飞机场调度模拟,根据不同的输入参数得到不同的模拟结果。程序运行开始,首先需要输入以下参数:

机场跑道数,飞机降落占用跑道时间(整数), 飞机起飞占用跑道时间(整数)

整个模拟的时间以分钟为单位,从 0 开始,每分钟的开始需要输入:

该分钟要求降落飞机数, 该分钟要求起飞飞机数

机场调度原则是降落优先起飞,在此原则下按来的顺序排队;每驾飞机都有一个编号,要起飞飞机从 1 开始,要降落飞机从 5001 开始;每驾飞机需要等待的时间是从其提要求开始到分配跑道为止;每个跑道都有一个编号(从 1 开始),都可以用来降落和起飞,但同一时间只能被一架飞机占用,占用时间为该飞机降落(起飞)占用跑道时间。

当输入的要求降落飞机数和要求起飞飞机数都小于 0 时,表示机场关闭,不再接受新的请求,但余下没有降落(起飞)的飞机需照常进行。

模拟过程中需要随时输出以下数据:

1. 当前时间 (%4d)

2. 所有从占用变为空闲的跑道编号 (在输入降落、起飞飞机数前输出)

3. 可以降落(起飞)飞机编号(% 04d )、跑道编号(% 02d ) (在输入降落、起飞飞机数后输出)

模拟结束后,程序需输出以下统计结果:

1. 模拟时间(% 4d )

2. 降落平均等待时间(% 4.1f )

3. 起飞平均等待时间(% 4.1f )

4. 每条跑道被占用时间(% 4d )

5. 跑道平均被占用的百分比(% 4.1f , 平均占用时间× 100/ 模拟时间)

例: (下面的黑斜体为输入)

4 3 5

Current Time: 0

1 4

airplane 5001 is ready to land on runway 01

airplane 0001 is ready to takeoff on runway 02

airplane 0002 is ready to takeoff on runway 03

airplane 0003 is ready to takeoff on runway 04

Current Time: 1

0 0

Current Time: 2

0 2

Current Time: 3

runway 01 is free

3 0

airplane 5002 is ready to land on runway 01

Current Time: 4

0 0

Current Time: 5

runway 02 is free

runway 03 is free

runway 04 is free

0 0

airplane 5003 is ready to land on runway 02

airplane 5004 is ready to land on runway 03

airplane 0004 is ready to takeoff on runway 04

Current Time: 6

runway 01 is free

2 4

airplane 5005 is ready to land on runway 01

Current Time: 7

-1 -1

Current Time: 8
runway 02 is free
runway 03 is free
airplane 5006 is ready to land on runway 02
airplane 0005 is ready to takeoff on runway 03
Current Time: 9
runway 01 is free
airplane 0006 is ready to takeoff on runway 01
Current Time: 10
runway 04 is free
airplane 0007 is ready to takeoff on runway 04
Current Time: 11
runway 02 is free
airplane 0008 is ready to takeoff on runway 02
Current Time: 12
Current Time: 13
runway 03 is free
airplane 0009 is ready to takeoff on runway 03
Current Time: 14
runway 01 is free
airplane 0010 is ready to takeoff on runway 01
Current Time: 15
runway 04 is free
Current Time: 16
runway 02 is free
Current Time: 17
Current Time: 18
runway 03 is free
Current Time: 19
runway 01 is free
simulation finished
simulation time: 19
average waiting time of landing: 1.0
average waiting time of takeoff: 4.2
runway 01 busy time: 19
runway 02 busy time: 16
runway 03 busy time: 18
runway 04 busy time: 15
runway average busy time percentage: 89.5%

 测试输入关于“测试输入”的帮助期待的输出关于“期待的输出”的帮助时间限制关于“时间限制”的帮助内存限制关于“内存限制”的帮助额外进程关于“{$a} 个额外进程”的帮助
测试用例 1以文本方式显示
  1. 1 2 3↵
  2. 1 2↵
  3. 2 1↵
  4. 0 0↵
  5. 0 0↵
  6. 0 0↵
  7. -1 -1↵
以文本方式显示
  1. Current Time:    0↵
  2. airplane 5001 is ready to land on runway 01↵
  3. Current Time:    1↵
  4. Current Time:    2↵
  5. runway 01 is free↵
  6. airplane 5002 is ready to land on runway 01↵
  7. Current Time:    3↵
  8. Current Time:    4↵
  9. runway 01 is free↵
  10. airplane 5003 is ready to land on runway 01↵
  11. Current Time:    5↵
  12. Current Time:    6↵
  13. runway 01 is free↵
  14. airplane 0001 is ready to takeoff on runway 01↵
  15. Current Time:    7↵
  16. Current Time:    8↵
  17. Current Time:    9↵
  18. runway 01 is free↵
  19. airplane 0002 is ready to takeoff on runway 01↵
  20. Current Time:   10↵
  21. Current Time:   11↵
  22. Current Time:   12↵
  23. runway 01 is free↵
  24. airplane 0003 is ready to takeoff on runway 01↵
  25. Current Time:   13↵
  26. Current Time:   14↵
  27. Current Time:   15↵
  28. runway 01 is free↵
  29. simulation finished↵
  30. simulation time:   15↵
  31. average waiting time of landing:  1.3↵
  32. average waiting time of takeoff:  8.7↵
  33. runway 01 busy time:   15↵
  34. runway average busy time percentage: 100.0%↵
1秒64M0

代码

#include<stdio.h>  
#include<string.h>  
#include<stdlib.h>  
#include<math.h>  
int main()  
{  
    int paodao,jiangluo,qifei;  
    int jiang,fei;  
    int i,j,k,m=0,n=0;  
    scanf("%d %d %d",&paodao,&jiangluo,&qifei);  
    int chang[paodao];  
    memset(chang,0,sizeof(chang));  
    int jiang1=0,fei1=0,time=0;  
    int flag=0;  
    int busy[paodao];  
    float busys=0;  
    float abusy=0;  
    for(i=0;i<paodao;i++)  
    {  
        busy[i]=0;  
    }  
    float wait1=0,wait2=0;  
    printf("Current Time:    0\n");  
    scanf("%d %d",&jiang,&fei);  
    jiang1+=jiang;  
    fei1+=fei;  
    while(jiang1>=0&&fei1>=0)  
    {  
        for(i=0;i<paodao;i++)  
        {  
            if(chang[i]==0)  
            {  
                if(jiang1>0)  
                {  
                    m+=1;  
                    printf("airplane %d is ready to land on runway %02d\n",5000+m,i+1);  
                    chang[i]=jiangluo;  
                    jiang1-=1;  
                }  
                else if(jiang1==0&&fei1!=0)  
                {  
                    n+=1;  
                    printf("airplane %04d is ready to takeoff on runway %02d\n",n,i+1);  
                    chang[i]=qifei;  
                    fei1-=1;  
                }     
            }  
            if(chang[i]!=0)  
            {  
                busy[i]++;  
            }  
        }  
        time+=1;  
        printf("Current Time: %4d\n",time);  
        if(jiang1>0)  
        {  
            wait1+=jiang1;  
        }  
        if(fei1>0)  
        {  
            wait2+=fei1;  
        }  
        for(i=0;i<paodao;i++)  
        {  
            if(chang[i]==1)  
            {  
                printf("runway %02d is free\n",i+1);  
                chang[i]=0;  
            }  
            else if(chang[i]>1)  
            {  
                chang[i]-=1;  
            }  
        }  
        scanf("%d %d",&jiang,&fei);  
        if(jiang>=0&&fei>=0)  
        {  
            jiang1+=jiang;  
            fei1+=fei;  
        }  
        else if(jiang<0&&fei<0)  
        {  
            break;  
        }  
    }  
    while(jiang1>=0&&fei1>=0)  
    {  
        flag=0;  
        for(i=0;i<paodao;i++)  
        {  
            if(chang[i]==0)  
            {  
                if(jiang1>0)  
                {  
                    m+=1;  
                    printf("airplane %d is ready to land on runway %02d\n",5000+m,i+1);  
                    chang[i]=jiangluo;  
                    jiang1-=1;  
                }  
                else if(jiang1==0&&fei1!=0)  
                {  
                    n+=1;  
                    printf("airplane %04d is ready to takeoff on runway %02d\n",n,i+1);  
                    chang[i]=qifei;  
                    fei1-=1;  
                }     
            }  
            if(chang[i]!=0)  
            {  
                busy[i]++;  
            }  
        }  
        time+=1;  
        printf("Current Time: %4d\n",time);  
        if(jiang1>0)  
        {  
            wait1+=jiang1;  
        }  
        if(fei1>0)  
        {  
            wait2+=fei1;  
        }  
        for(i=0;i<paodao;i++)  
        {  
            if(chang[i]==1)  
            {  
                printf("runway %02d is free\n",i+1);  
                chang[i]=0;  
            }  
            else if(chang[i]>1)  
            {  
                chang[i]-=1;  
            }  
        }  
        if(jiang1==0&&fei1==0)  
        {  
            for(i=0;i<paodao;i++)  
            {  
                if(chang[i]!=0)  
                {  
                    flag=1;  
                }  
            }  
            if(flag==0)  
            {  
                break;  
            }  
        }  
    }  
    printf("simulation finished\n");  
    printf("simulation time: %4d\n",time);  
    float await1,await2;  
    await1=wait1/m;  
    await2=wait2/n;  
    printf("average waiting time of landing: %4.1f\n",await1);  
    printf("average waiting time of takeoff: %4.1f\n",await2);  
    for(i=0;i<paodao;i++)  
    {  
        printf("runway %02d busy time: %4d\n",i+1,busy[i]);  
        busys+=busy[i];  
    }  
    abusy=(busys*100)/(time*paodao);  
    printf("runway average busy time percentage: %4.1f%%\n",abusy);  
}  
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值