1 / 7

Camlot 解题报告 IOI’98 Day 2 Problem 2

Camlot 解题报告 IOI’98 Day 2 Problem 2. 赵静 2003 年 7 月 12 日. 游戏描述. 初始状态:一个国王和 N 个骑士分布在 8*8 的棋盘上 0 <= N <= 63 目标状态:国王和所有的骑士走到同一个格子里 游戏规则: 在一次移动中,国王可以走到相邻的八个格子里 骑士可以走八个方向的“日”字 国王和某个骑士相遇后,可以由骑士带着移动 任务:用最少的总移动步数达到目标状态。. Sample. 8 7 6 5 4 3 2 1. Input:. D4A3A8H1H8. Output:.

Télécharger la présentation

Camlot 解题报告 IOI’98 Day 2 Problem 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Camlot 解题报告IOI’98 Day 2 Problem 2 赵静 2003年7月12日

  2. 游戏描述 • 初始状态:一个国王和N个骑士分布在8*8的棋盘上 • 0 <= N <= 63 • 目标状态:国王和所有的骑士走到同一个格子里 • 游戏规则: • 在一次移动中,国王可以走到相邻的八个格子里 • 骑士可以走八个方向的“日”字 • 国王和某个骑士相遇后,可以由骑士带着移动 • 任务:用最少的总移动步数达到目标状态。

  3. Sample 8 7 6 5 4 3 2 1 Input: D4A3A8H1H8 Output: 10 A B C D E F G H

  4. 分析 • 最短路问题 • 求一个点,使其到已知若干点的总路径最短 • 点的个数有限(64个),逐个枚举 • 国王和骑士相遇的特殊情形 • 国王可能和任意一个骑士在任意一点相遇 • 枚举63 * 64种可能

  5. 枚举法 • 预处理:用Floyd算法求出骑士在任意两点间的最短路径 • 枚举过程:O ( 64 * 64 * N) ans = INT_MAX; for ( i 取遍棋盘上的64个点) { sum = 每个骑士到 i 的距离之和; for ( j 取遍棋盘上的64个点) { tmp1 = 国王到点 j 的距离; // 怎样计算? tmp2 = min { 骑士 k 经过 j 到 i 的距离 - 骑士 k 到 i 的距离 }; // k 取遍所有骑士 ans = min {ans, sum + tmp1 + tmp2}; } }

  6. 递推算法(供参考) • CK [ i ] [ j ] 骑士从 i 到 j 的距离 • CKK [ i ] [ j ] 国王从 i 到 j 的距离 • CG [ i ] = sum { CK [ knight [ j ] ] [ i ] },j 取遍所有骑士 • 所有骑士在 i 相遇的总距离 • MKK [ i ] [ j ] = CK [ knight [ i ] ] [ j ] + CKK [ king ] [ j ] • 国王和第 i 个骑士在 j 相遇的距离 • MKM [ i ] [ j ] = min { MKK [ i ] [ k ] + CK [ k ] [ j ] + CG [ j ] – CK [ knight [ i ] ] [ j ] } • 第 i 个骑士带着国王和其它骑士在 j 相遇的总距离 • ans = min { MKM [ i ] [ j ] },i 取遍所有骑士,j 取遍64个点

  7. THE END • Thank you for your attention!

More Related