建设网站公司中网站方案范文
2026/6/9 17:19:32 网站建设 项目流程
建设网站公司中,网站方案范文,一级消防工程师考试科目,青岛做网站哪里好何为事件驱动#xff1f;1 时间范围很大2 真正有用的信息只发生在少数时间3 中间有一大段时间的规则是线性的4 暴力容易超时思路#xff1a;第一步记录所有事件#xff0c;第二步按照时间排序#xff0c;第三步事件发生-先补中间时间-再处理事件#xff0c;第四步…何为事件驱动1 时间范围很大2 真正有用的信息只发生在少数时间3 中间有一大段时间的规则是线性的4 暴力容易超时思路第一步记录所有事件第二步按照时间排序第三步事件发生-先补中间时间-再处理事件第四步最后补到终点时间。具体模版定义内部类static class Event { int time; // 事件发生时间 int id; // 对象编号人 / 店 / 设备 Event(int t, int i) { time t; id i; } }读入加排序Event[] events new Event[m]; for (int i 0; i m; i) { events[i] new Event(sc.nextInt(), sc.nextInt()); } Arrays.sort(events, (a, b) - a.time - b.time);状态数组三件套int[] value new int[n 1]; // 当前数值分数 / 能量 / 状态 int[] last new int[n 1]; // 上一次事件时间 boolean[] flag new boolean[n 1]; // 是否满足某条件核心模版for (Event e : events) { int t e.time; int id e.id; //补中间时间跳过 value[id] Math.max(0, value[id] - (t - last[id] - 1)); //处理当前事件 value[id] 事件带来的变化; //状态判断 if (value[id] 上限) flag[id] true; if (value[id] 下限) flag[id] false; //更新时间 last[id] t; }尾处理容易忘for (int i 1; i n; i) { value[i] Math.max(0, value[i] - (END - last[i])); if (value[i] 下限) flag[i] false; }输出答案int res 0; for (int i 1; i n; i) { if (flag[i]) res; } System.out.println(res);例外卖优先级问题import java.util.*; public class Main { static class Order { int time, shop; Order(int t, int s) { time t; shop s; } } public static void main(String[] args) { Scanner sc new Scanner(System.in); int n sc.nextInt(); // 店铺数 int m sc.nextInt(); // 订单数 int T sc.nextInt(); // 截止时间 Order[] orders new Order[m]; for (int i 0; i m; i) { orders[i] new Order(sc.nextInt(), sc.nextInt()); } // 按时间排序 Arrays.sort(orders, (a, b) - a.time - b.time); int[] score new int[n 1]; // 当前优先级 int[] last new int[n 1]; // 上一次接单时间 boolean[] in new boolean[n 1];// 是否在优先缓存 // 事件驱动处理订单 for (Order o : orders) { int t o.time; int s o.shop; // 中间空闲时间衰减 score[s] Math.max(0, score[s] - (t - last[s] - 1)); // 当前订单 score[s] 2; // 状态判断 if (score[s] 5) in[s] true; if (score[s] 3) in[s] false; last[s] t; } // 尾处理最后一次订单到 T for (int i 1; i n; i) { score[i] Math.max(0, score[i] - (T - last[i])); if (score[i] 3) in[i] false; } // 统计答案 int res 0; for (int i 1; i n; i) { if (in[i]) res; } System.out.println(res); } }主要还是事件的更新

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询