问题描述:某银行有一个客户办理业务站,在单位时间内随机地有客户到达,设每位客户的业务办理时间是某个范围的随机值。设只有一个窗口,一位业务人员,要求程序模拟统计在设定时间内,业务人员的总空闲时间和客户的

该博客介绍了一个模拟问题,涉及银行客户随机到达并办理业务的场景。只有一个窗口和业务人员,每个客户的业务处理时间为随机值。文章旨在通过程序计算在特定时间内的业务人员空闲时间和客户等待情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:某银行有一个客户办理业务站,在单位时间内随机地有客户到达,设每位客户的业务办理时间是某个范围的随机值。设只有一个窗口,一位业务人员,要求程序模拟统计在设定时间内,业务人员的总空闲时间和客户的

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define OVERFLOW -2
typedef struct{
   
	 int arrive;
     int treat;   //客户的信息结构
}QNODE;
typedef struct node{
   
     QNODE data;   //结构体嵌套
     struct node *next;  //队列中的元素信息
}LNODE;
LNODE *front,*rear;    // 队头指针和队尾指针
QNODE curr,temp;      //客户类型
char Fname[120];     //读取文件的文件名    将那串数据放在文本里
    FILE*fp;           //文本指针
void EnQueue(LNODE**hpt,LNODE**tpt,QNODE e){
      //入队列  列队 队尾插入   对头删除  
	LNODE*p=(LNODE*)malloc(sizeof(LNODE));   
客户业务分为两种, 第一种是申请从银行得到一笔资金,即取款或者借款。 第二种是向银行投入一笔资金,即存款或者还款。 Void Action() 银行有两个服务窗口,相应的有两个队列。 客户到达银行后先排第一个队。queue <int> q1; 处理每个客户业务时,如果属于第一种,且申请额超 出银行现存资金额而得不到满足,则立即排入第二个队 queue <int> q2; 等候,直至满足时才离开银行 ;否则业务处理完后立即离开银行。 每接待完一个第二种业务客户,则顺序检查处理 (如果可能)第二个队列中的客户,对能满足的申请者予以满足,不能满足的者重新排到 第二个队列的队尾。 注意: 在此检查过程中,一旦银行的资金额少于或者等于刚才第一个队列中最后一个客 户(第二种业务)被接待之前的数额,或者本次已将第二个队列检查或处理了一遍,就停 止检查(因为此时已不可能还有能满足者)转而继续接待第一个队列客户。任何时刻都只 开一个窗口。假检查不需要时间。营业时间结束时所有客户立即离开银行。 【基本要求】 利用动态存储结构实现模拟。 【测试数据】 一天营业开始时银行拥有的款额为10000(元) 初始化total=10000; ,营业时间为600(分钟)。 设定营业时间为早上9:00-晚上19:00 其他模拟参量自定,注意测定两种极端的情况:一是两个到达事件之间的间隔时间很短, 而客户的交易时间很长,另一个恰好相反,置两个到达事件的间隔时间很长,而客户的 交易时间很短。这个有点焦虑 【实现提示】 事件有两类:到达银行离开银行。初始时银行现存资金额为total。开 始营业后的第一个事件是客户到达设定一个计数器count来计算一天内客户人数,初始化为0 营业时间从0到closetime。到达事件发生时随机置 此客户的交易时间距下一到达事件之间的时间间隔。每一个客户办理的款额也是随机 确定的,用负分别表示第一类第二类业务。 个人觉得用0、1、2、3分别表示取款、借款、存款、还款比较好。 变量total,closetime以及上述两个随机量的上下界均交互地从终端读入,作为模拟参数。 两个队列一个事件表均要用动态存储结构实现。需考虑置离开事件,以及如何 计第二个队列的存储结构以获得较高的效率。注意:事件表是按时间顺序有序的。 void getTime();
银行有n个窗口对外接待客户,从早晨银行9点开门起到5点关门,不断有客户进入银行,由于每个窗口在某个时刻只能接待一个客户。因此在客户人数众多时需要在每个窗口前顺次排队,对于刚进银行客户。如果某个窗口业务员正空闲,则可上前输业务。反之,若个窗口均有客户所占,他便会排在为数最少的队伍后面。编制一个程序模拟银行的这种业务活动并计算一天中客户银行的平均逗留时间。 首先从题目分析:N个窗口排队,首先就要建立N个队列来存储排队的用户信息 ,然后算出那个队列最短就用户就到那个队伍排队,同时通过随机生成他办理业务时间到来的时间,通过计算用户的到来时间离开时间就可以计算出某个用户在银行的逗留时间 ;话不多说直接上代码。 下面是主函数,由用户输入银行上下班时间,计算营业多长时间Total_time,如何当前时间小于关门的时间,就一直进入customer_into();函数,用户不断的进来 #define FALSE 0 #define TRUE 1 #define QUEUE_SUM 4 //窗口的数量 int rand_business_time=0, rand_wait_time=0;//定义办理时间,等待时间变量 int Total_time=0,now_tim=0;//时间,当前时间 int go_time[4] = {0,0,0,0};//定义数组存储每个窗口最后一位办理业务时间 int sum_nan[4] = {0,0,0,0};//定义数组存储每个窗口排队的人数 int Sign=TRUE; //是否关门标志位 float Sum_Wait_Time=0.0; //等待的时间 float Sun_Nan=0.0; //人数 int open_time;//开门时间 int off_time; //关门时间 int main() { Prompted(); printf("输入银行的24小时制营业时间:如营业时间为9:00--17:00,则应输入:9,17\n"); scanf("%d,%d", &open;_time,&off;_time); Total_time = (off_time - open_time) * 60;//计算银行营业多少分钟 for (int i = 0; i now_time) { customer_into(); //客户进入函数 } printf("银行关门时间到不再接收客人\n\n"); for (int i = 0; i < QUEUE_SUM; i++) { DisposeQueue(&queue;[i],i);//输入在银行关门前还没有办理业务客户信息 } printf("平均时间为%.2f分钟",Sum_Wait_Time/Sun_Nan); /*通过各个客户等待时间/人数算出逗留平均时间*/ _getch(); return 0; }
以下是基于队列的C语言程序实现: ```c #include <stdio.h> #include <stdlib.h> #include <time.h> #define MAX_QUEUE_SIZE 100 // 队列最大长度 #define MAX_SERVICE_TIME 10 // 最大业务办理时间 #define MIN_SERVICE_TIME 1 // 最小业务办理时间 // 客户结构体 typedef struct { int arrive_time; // 到达时间 int service_time; // 业务办理时间 int start_time; // 开始办理时间 int end_time; // 结束办理时间 } Customer; // 队列结构体 typedef struct { Customer data[MAX_QUEUE_SIZE]; int front; // 队头指针 int rear; // 队尾指针 } Queue; // 初始化队列 void initQueue(Queue *queue) { queue->front = queue->rear = 0; } // 判断队列是否为空 int isQueueEmpty(Queue *queue) { return queue->front == queue->rear; } // 判断队列是否已满 int isQueueFull(Queue *queue) { return (queue->rear + 1) % MAX_QUEUE_SIZE == queue->front; } // 入队 int enQueue(Queue *queue, Customer customer) { if (isQueueFull(queue)) { return 0; } queue->data[queue->rear] = customer; queue->rear = (queue->rear + 1) % MAX_QUEUE_SIZE; return 1; } // 出队 int deQueue(Queue *queue, Customer *customer) { if (isQueueEmpty(queue)) { return 0; } *customer = queue->data[queue->front]; queue->front = (queue->front + 1) % MAX_QUEUE_SIZE; return 1; } int main() { Queue queue; initQueue(&queue); int total_idle_time = 0; // 空闲时间 int total_wait_time = 0; // 等待时间 int total_serve_time = 0; // 办理时间 int total_customer = 0; // 客户数 int current_time = 0; // 当前时间 int service_start_time = 0; // 当前业务开始时间 int service_end_time = 0; // 当前业务结束时间 srand(time(NULL)); // 初始化随机种子 FILE *fp = fopen("text.txt", "r"); // 打开文件 if (fp == NULL) { printf("File open failed!\n"); return -1; } while (!feof(fp)) { int arrive_time, service_time; fscanf(fp, "%d %d", &arrive_time, &service_time); // 从文件中读取数据 Customer customer = {arrive_time, service_time, 0, 0}; if (customer.arrive_time >= current_time) { // 业务人员空闲 total_idle_time += customer.arrive_time - current_time; service_start_time = customer.arrive_time; } else { // 业务人员忙碌 service_start_time = current_time; } service_end_time = service_start_time + customer.service_time; // 计算业务结束时间 customer.start_time = service_start_time; customer.end_time = service_end_time; enQueue(&queue, customer); // 将客户加入队列 total_serve_time += customer.service_time; // 更新办理时间 current_time = customer.arrive_time; // 更新当前时间 while (!isQueueEmpty(&queue)) { Customer front; if (deQueue(&queue, &front)) { total_wait_time += current_time - front.arrive_time; // 更新等待时间 current_time = front.end_time; // 更新当前时间 total_customer++; // 更新客户数 } else { break; } } } fclose(fp); // 关闭文件 printf("Total idle time: %d\n", total_idle_time); printf("Average waiting time: %.2f\n", (float)total_wait_time / total_customer); return 0; } ``` 程序中使用了两个结构体,一个客户结构体,包括客户到达时间业务办理时间、开始办理时间结束办理时间;另一个是队列结构体,包括队列数据队头、队尾指针。程序中使用了队列来模拟客户排队等待办理业务的过程。 程序中先从文件中读取客户到达时间需要办理业务时间,然后判断业务人员是否空闲,计算业务开始时间结束时间,并将客户加入队列。接着,程序从队列中取出客户进行业务办理,更新等待时间客户当前时间。最后统计空闲时间平均等待时间,并输出结果。 程序中使用了随机数生成客户业务办理时间,为了使结果更加真实,可以根据实际情况调整最大最小业务办理时间
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值