From 3fd8360cb3b145f5170b27cadf4b9661a16266d6 Mon Sep 17 00:00:00 2001 From: pwgliku62 <2867008117@qq.com> Date: Mon, 10 Jun 2024 22:23:06 +0800 Subject: [PATCH] =?UTF-8?q?Delete=20'=E9=93=B6=E8=A1=8C=E9=97=AE=E9=A2=981?= =?UTF-8?q?.txt'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 银行问题1.txt | 75 ----------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 银行问题1.txt diff --git a/银行问题1.txt b/银行问题1.txt deleted file mode 100644 index 07d6151..0000000 --- a/银行问题1.txt +++ /dev/null @@ -1,75 +0,0 @@ -import java.util.*; - -public class BankQueue { - - static class Customer { - int arrivalTime; - int processTime; - - public Customer(int arrivalTime, int processTime) { - this.arrivalTime = arrivalTime; - this.processTime = processTime; - } - } - - public static double calculateAverageWaitTime(List customers, int maxProc, int maxWindow) { - Queue[] windows = new LinkedList[maxWindow]; - for (int i = 0; i < maxWindow; i++) { - windows[i] = new LinkedList<>(); - } - - int totalWaitTime = 0; - int numCustomersServed = 0; - - for (Customer customer : customers) { - // 寻找最早空闲的窗口 - int minFinishTime = Integer.MAX_VALUE; - int chosenWindow = -1; - - for (int i = 0; i < maxWindow; i++) { - if (windows[i].isEmpty()) { - chosenWindow = i; - break; - } - int finishTime = windows[i].peek(); - if (finishTime < minFinishTime) { - minFinishTime = finishTime; - chosenWindow = i; - } - } - - // 计算等待时间 - int waitTime = Math.max(0, minFinishTime - customer.arrivalTime); - totalWaitTime += waitTime; - - // 更新服务结束时间 - int serviceEndTime = customer.arrivalTime + waitTime + customer.processTime; - if (serviceEndTime - customer.arrivalTime <= maxProc) { - windows[chosenWindow].offer(serviceEndTime); - numCustomersServed++; - } - } - - if (numCustomersServed == 0) { - return 0; // 没有顾客被服务 - } - - return (double) totalWaitTime / numCustomersServed; - } - - public static void main(String[] args) { - // 假设的输入数据 - List customers = Arrays.asList( - new Customer(0, 3), - new Customer(2, 3), - new Customer(5, 4), - new Customer(6, 2) - ); - - int maxProc = 10; - int maxWindow = 2; - - double avgWaitTime = calculateAverageWaitTime(customers, maxProc, maxWindow); - System.out.println("平均等待时间: " + avgWaitTime); - } -} \ No newline at end of file