离散事件模拟-银行管理

来源:互联网 发布:金字塔期货交易软件 编辑:程序博客网 时间:2024/05/17 07:40

Problem Description

 

现在银行已经很普遍,每个人总会去银行办理业务,一个好的银行是要考虑 平均逗留时间的,即: 在一定时间段内所有办理业务的人员逗留的时间的和/ 总的人数。逗留时间定义为 人员离开的时间减去人员来的时间。银行只有考虑了这一点,我们在办理业务的时候,才不会等太多的时间。

为了简化问题,我们认为银行只有一号窗口和二号窗口可以办理业务 ,并且在时间范围是12<=time<=18,即从中午十二点到晚上十八点,输入数据采用分钟即0代表中午12点,60代表下午一点,90代表下午一点半… 这样time>=0&&time<=360, 如果来的时间超出这个时间段不接受(办理时间不受限制)。每个人到达的时间都不一样。顾客到达的时候,总是前往人数少的那个窗口。如果人数相当或者两个窗口都没有人总是前往1号窗口。请计算平均逗留时间=总逗留的分钟数/总的人数。

Input

 

第一行一个整数t(0 < t <= 100), 代表输入的组数。

对于每一组输入一个整数n (0 < n <= 100),代表有n个人。然后是n行,每行有两个数据 x 与 y。 x代表顾客到达时间,y代表办理业务需要的时间。x, y 为整数(0 <= x <= 360)(y > 0 && y <= 15)。数据保证按顾客来的先后顺序输入。

Output

 

对于每组数据输出平均逗留时间,保留两位小数。

Example Input

1160 10

Example Output

10.00

Hint

#include<stdio.h>#include<stdlib.h>typedef int QElemType;typedef struct{    QElemType line[300];    int head;    int tail;}SqQueue;void InitQueue(SqQueue &x){    x.head = 0; //初始化两个指针    x.tail = 0;}int line(SqQueue &x, int now){    if(x.head != 0)    {        while(x.line[x.head] <= now)            {                x.head++; //这里出错纠结了一个小时 很难受 之前if在这句话上面 导致会出现在head>tail的情况下结束循环的可能                if(x.head > x.tail)                {                    x.head = 0;                    x.tail = 0;                    break;                }            }        if(x.head == 0)                return 0;        else                {                    int num = x.tail - x.head + 1;                    return num;                }    }    else        return 0;}int add(SqQueue &l, int x, int y){    if(l.head == 0)    {        l.head = 1;        l.tail = 1;        l.line[1] = x + y;        return y;    }    else    {        l.tail++;        l.line[l.tail ] = l.line[l.tail - 1] + y; //数组存储每一个人的离开时间        return (l.line[l.tail - 1] - x + y);    }}int main()  /*之前一直在找错然后把主函数搞得各种繁琐 懒得改了=。=  一个小错误引发各种猜想 甚至有考虑过如果一个顾客等到360该怎么算  最后蒙到了一个错误数据然后找到了错误  果然还是自己太弱)*/{    int t;    int x, y;    int num1, num2;    scanf("%d", &t);    double time;    while(t--)    {        time        = 0;        SqQueue A;        SqQueue B;        InitQueue(A);        InitQueue(B);        int n;        scanf("%d", &n);        int i = 0;        int du;        for(i = 0; i <n; i++)        {            scanf("%d %d", &x, &y);            num1 = line(A, x);            num2 = line(B, x);            if(num1 <= num2)            {                du = add(A, x, y);                time += du;            }            else            {                du = add(B, x, y);                time += du;            }        }        double result;        result = time*1.0/n;        printf("%.2lf\n", result);    }    return 0;}


原创粉丝点击