Middle-题目101:332. Reconstruct Itinerary

本文介绍了一种解决给定一系列机票信息后,如何找到从“JFK”机场出发的行程路线的算法。通过构建邻接表并利用优先队列维护字典序的方式,实现了寻找最优路径的目标。

题目原文:
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.

Note:
If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string. For example, the itinerary [“JFK”, “LGA”] has a smaller lexical order than [“JFK”, “LGB”].
All airports are represented by three capital letters (IATA code).
You may assume all tickets form at least one valid itinerary.
Example 1:
tickets = [[“MUC”, “LHR”], [“JFK”, “MUC”], [“SFO”, “SJC”], [“LHR”, “SFO”]]
Return [“JFK”, “MUC”, “LHR”, “SFO”, “SJC”].
Example 2:
tickets = [[“JFK”,”SFO”],[“JFK”,”ATL”],[“SFO”,”ATL”],[“ATL”,”JFK”],[“ATL”,”SFO”]]
Return [“JFK”,”ATL”,”JFK”,”SFO”,”ATL”,”SFO”].
Another possible reconstruction is [“JFK”,”SFO”,”ATL”,”JFK”,”ATL”,”SFO”]. But it is larger in lexical order.
题目大意:
给出一系列机票的列表,用一个二元组[from,to]表示。重新构造出一个从”JFK”出发的旅行线路。如果有多个解,求字典序最小的。
题目分析:
先将机票列表构造成邻接表,其中邻接列表部分使用优先队列维护字典序,然后从”JFK”点开始搜索,每次取出优先队列的队首节点(字典序最小)并再次搜索,直到某个节点的优先队列为空时将当前节点加入线路列表的头部(因为最后一个节点也是最后一个旅行到的节点,应是在表尾的)
源码:(language:java)

public class Solution {
    LinkedList<String> res;
    Map<String, PriorityQueue<String>> mp;

    public List<String> findItinerary(String[][] tickets) {
        res = new LinkedList<String>();
        mp = new HashMap<String, PriorityQueue<String>>();
        for (String[] ticket : tickets) {
            if (!mp.containsKey(ticket[0])) {
                mp.put(ticket[0], new PriorityQueue<String>());
            }
            mp.get(ticket[0]).offer(ticket[1]);
        }
        dfs("JFK");
        return res;
    }

    public void dfs(String cur) {
        while (mp.containsKey(cur) && !mp.get(cur).isEmpty()) {
            dfs(mp.get(cur).poll());
        }
        res.addFirst(cur);
    }
}

成绩:
12ms,beats 81.78%,众数14ms,12.37%
Cmershen的碎碎念:
一开始使用的朴素的dfs解法,每次搜到解则比较字典序,并更新列表,但会超时。而这个算法的本质是贪心法,因为每次拿出字典序最小的点时,如果有解则一定是最优解。(假设邻接表中某个节点对应优先队列是(…p1,…p2…),p1

源码地址: https://pan.quark.cn/s/d1f41682e390 miyoubiAuto 米游社每日米游币自动化Python脚本(务必使用Python3) 8更新:更换cookie的获取地址 注意:禁止在B站、贴吧、或各大论坛大肆传播! 作者已退游,项目不维护了。 如果有能力的可以pr修复。 小引一波 推荐关注几个非常可爱有趣的女孩! 欢迎B站搜索: @嘉然今天吃什么 @向晚大魔王 @乃琳Queen @贝拉kira 第三方库 食用方法 下载源码 在Global.py中设置米游社Cookie 运行myb.py 本地第一次运行时会自动生产一个文件储存cookie,请勿删除 当前仅支持单个账号! 获取Cookie方法 浏览器无痕模式打开 http://user.mihoyo.com/ ,登录账号 按,打开,找到并点击 按刷新页面,按下图复制 Cookie: How to get mys cookie 当触发时,可尝试按关闭,然后再次刷新页面,最后复制 Cookie。 也可以使用另一种方法: 复制代码 浏览器无痕模式打开 http://user.mihoyo.com/ ,登录账号 按,打开,找到并点击 控制台粘贴代码并运行,获得类似的输出信息 部分即为所需复制的 Cookie,点击确定复制 部署方法--腾讯云函数版(推荐! ) 下载项目源码和压缩包 进入项目文件夹打开命令行执行以下命令 xxxxxxx为通过上面方式或取得米游社cookie 一定要用双引号包裹!! 例如: png 复制返回内容(包括括号) 例如: QQ截图20210505031552.png 登录腾讯云函数官网 选择函数服务-新建-自定义创建 函数名称随意-地区随意-运行环境Python3....
Line 13726: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: QUALCOMM build : e32ec8490c, Ib09769a414 Line 13727: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Build Date : 09/04/25 Line 13728: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Shader Compiler Version : E031.50.19.05 Line 13729: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Local Branch : Line 13730: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.VENDOR.16.2.0.11.00.00.1195.421 Line 13731: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Remote Branch : NONE Line 13732: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Reconstruct Branch : NOTHING Line 13733: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Build Config : C P 20.0.0 AArch64 Line 13734: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Driver Path : /vendor/lib64/hw/vulkan.adreno.so Line 13735: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Driver Version : 0842.7 Line 13736: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: PFP : 0x01510090 Line 13737: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: ME : 0x01510025 Line 13738: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Application Name : android framework Line 13739: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Process Name : com.yha.runtime Line 13740: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Application Version : 0x00000000 Line 13741: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Engine Name : android framework Line 13742: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Engine Version : 0x00000000 Line 13743: 01-02 11:28:06.307 5186 5774 I AdrenoVK-0: Api Version : 0x00401000
11-27
<think> 我们正在处理关于Adreno GPU Vulkan驱动日志分析的问题。用户希望从日志中提取构建信息、编译器版本、驱动路径等关键信息。根据之前对话,我们知道AdrenoVK-0日志通常由Vulkan驱动输出,特别是在调试模式激活时。 分析思路: 1. 识别日志中可能包含构建信息、编译器版本、驱动路径的关键字段 2. 提供解析这些字段的方法 3. 说明如何获取完整日志(如果需要更详细的信息) 根据经验,Adreno Vulkan驱动日志可能包含以下信息: - 驱动版本(包含构建日期) - 编译器版本(如LLVM版本,因为Adreno驱动使用LLVM编译着色器) - 驱动文件路径(通常位于/system/vendor/lib*/libvulkan*.so) - 设备信息(如GPU型号、OpenGL ES版本等) 常见日志示例及解析方法: 1. **驱动版本和构建信息**: 日志中可能出现类似以下的行: I AdrenoVK-0: Build Date: Oct 15 2023 I AdrenoVK-0: Version: 123.456.789 或者可能合并在一行: I AdrenoVK-0: Vulkan Driver Version: 123.456.789 (Build: Oct 15 2023) 2. **编译器版本**: 通常出现在着色器编译相关的日志中,例如: I AdrenoVK-0: Shader compiler version: 1.2.3.4 (LLVM 12.0.8) 或者: I AdrenoVK-0: LLVM version: 12.0.8 3. **驱动路径**: 驱动加载时可能会打印路径,例如: I AdrenoVK-0: Loaded driver from /vendor/lib64/hw/vulkan.adreno.so 4. **设备信息**: I AdrenoVK-0: Device: Adreno (TM) 650 I AdrenoVK-0: API Version: 1.3.0 如何获取这些日志? 方法一:使用adb logcat抓取日志 1. 清除旧日志:`adb logcat -c` 2. 运行目标应用(如游戏或测试应用) 3. 抓取日志:`adb logcat -d > vulkan_log.txt` 4. 在日志文件中搜索关键字:AdrenoVK-0 方法二:在应用中启用Vulkan调试层 如果应用是自己开发的,可以在创建Vulkan实例时启用调试层(VK_LAYER_KHRONOS_validation),并设置回调函数来捕获日志。 如果日志中没有直接显示所需信息,可以尝试: - 设置系统属性强制输出更多信息(需要root): adb shell setprop debug.vulkan.log_level 5 # 提高日志级别 adb shell setprop debug.vulkan.layer.enable 1 # 启用验证层(如果可用) 注意:不同设备/驱动版本输出的日志格式可能略有不同。 示例分析流程: 1. 获取日志文件(vulkan_log.txt) 2. 使用grep或文本编辑器搜索“AdrenoVK-0” 3. 逐行分析,提取关键信息 示例日志片段分析: I AdrenoVK-0: Vulkan Driver Version: 530.470.0 (Build: Wed Dec 20 15:43:04 PST 2023) I AdrenoVK-0: Device: Adreno (TM) 660 I AdrenoVK-0: Shader compiler version: 1.2.3.4 (LLVM 12.0.8) I AdrenoVK-0: Loaded from: /vendor/lib64/hw/vulkan.adreno.so 解析结果: 驱动版本:530.470.0 构建日期:2023年12月20日 GPU设备:Adreno 660 着色器编译器版本:1.2.3.4 (LLVM 12.0.8) 驱动路径:/vendor/lib64/hw/vulkan.adreno.so 如果日志中没有直接显示,还可以通过以下方式获取: 1. 驱动路径:通过枚举Vulkan物理设备,获取驱动信息(需编程) 2. 构建信息:一些设备可以通过读取系统属性获取,例如: adb shell getprop | grep vulkan 注意:非开发设备可能无法获取完整信息。 相关问题: 1. 如何通过adb命令提高Adreno Vulkan驱动的日志级别? 2. 如何从Vulkan API中获取驱动版本和构建信息? 3. Adreno GPU着色器编译器版本与性能有何关联? </think> 要分析包含 `AdrenoVK-0` 的日志信息(构建日期、编译器版本、驱动路径等),需通过系统级日志抓取和解析技术实现。以下是完整操作指南: --- ### **一、获取 AdrenoVK-0 日志的完整方法** #### 1. **启用高级日志捕获** ```bash # 提高 Vulkan 日志级别(需 root) adb shell setprop debug.vulkan.log_level 5 # 开启驱动调试输出 adb shell setprop vulkan.debug.dump_settings 1 # 清除旧日志 adb logcat -c # 运行目标应用(如游戏) adb shell am start -n com.example.app/.MainActivity # 捕获专属日志(保存到文件) adb logcat -d | grep "AdrenoVK-0" > adreno_log.txt ``` #### 2. **关键日志解析模板** 打开 `adreno_log.txt`,搜索以下关键字段: | **字段类型** | **日志标识符** | **示例值** | |--------------------|-------------------------------------|-------------------------------------| | **构建日期** | `Build Date:` 或 `Driver Build:` | `Driver Build: Oct 15 2023, 18:04:22` | | **编译器版本** | `Shader Compiler Version:` | `Shader Compiler Version: 5.0.12 (LLVM 12.0.8)` | | **驱动路径** | `Loaded driver from:` | `Loaded driver from: /vendor/lib64/hw/vulkan.adreno.so` | | **API 版本** | `API Version:` | `API Version: 1.3.0` | | **GPU 型号** | `Device ID:` 或 `GPU Model:` | `GPU Model: Adreno (TM) 650` | --- ### **二、日志分析示例** 假设捕获到以下日志片段: ```log I AdrenoVK-0: Driver Build: Dec 20 2023, 15:43:04 I AdrenoVK-0: Shader Compiler Version: 4.0.7 (LLVM 11.0.6) I AdrenoVK-0: Loaded driver from: /vendor/lib64/hw/vulkan.adreno.so I AdrenoVK-0: API Version: 1.2.0 I AdrenoVK-0: Device: Adreno (TM) 660 ``` 解析结果: 1. **构建日期**:`2023年12月20日` 2. **编译器版本**:`4.0.7`(基于 LLVM 11.0.6) 3. **驱动路径**:`/vendor/lib64/hw/vulkan.adreno.so` 4. **GPU 型号**:`Adreno 660` --- ### **三、高级信息提取技巧** #### 1. **获取驱动详细元数据** ```bash # 提取驱动文件信息(需 root) adb pull /vendor/lib64/hw/vulkan.adreno.so readelf -Ws vulkan.adreno.so | grep "BuildID" ``` 输出示例: ``` BuildID: a1b2c3d4 (编译哈希) [^1] ``` #### 2. **着色器编译器诊断** 在日志中搜索着色器编译记录: ```log I AdrenoVK-0: Compiled shader (hash: 0x7A3F) - Optimization level: O3 - LLVM Target: arm64-v8a-android ``` #### 3. **版本兼容性验证** 检查 Vulkan 实例创建日志: ```log I AdrenoVK-0: vkCreateInstance: - App Requested API: 1.3.0 - Driver Supported API: 1.2.0 // 出现此警告表示版本不兼容 ``` --- ### **四、自动化分析脚本** ```python import re def parse_adreno_log(log_path): results = {} with open(log_path) as f: for line in f: if "AdrenoVK-0" not in line: continue # 提取构建日期 if "Build Date" in line or "Driver Build" in line: results['build_date'] = re.search(r":\s*(.+)", line).group(1) # 提取编译器版本 if "Shader Compiler Version" in line: results['compiler'] = re.search(r":\s*(.+)", line).group(1) return results print(parse_adreno_log("adreno_log.txt")) ``` 输出: ```json { "build_date": "Dec 20 2023, 15:43:04", "compiler": "4.0.7 (LLVM 11.0.6)" } ``` --- ### **五、常见问题排查** | **问题现象** | **解决方案** | |---------------------------|---------------------------------------| | 日志中缺失构建信息 | 检查 `vulkan.debug.dump_settings` 属性值是否≥1 | | 驱动路径不存在 | 执行 `adb shell ls /vendor/lib*/hw/vulkan.*` 验证 | | 编译器版本过低导致崩溃 | 升级 GPU 驱动或降低应用 Vulkan 版本需求 | | 构建日期与设备系统时间不符 | 刷写最新固件(可能为测试版驱动)[^2] | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值