zoukankan      html  css  js  c++  java
  • 洛谷 P3019 [USACO11MAR]会见点Meeting Place

    题目背景

    征求翻译。如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献。

    题目描述

    Bessie and Jonell are great friends. Since Farmer John scrambles where the cows graze every day, they are sometimes quite far from each other and can't talk.

    The pastures and paths on FJ's farm form a 'tree' structure. Each pasture has exactly one distinct path to any other pasture, and each pasture (except pasture #1, the 'root') also has a single parent node.

    Bessie and Jonell have decided that they will always meet at the closest pasture that that is both an ancestor of Jonell's pasture and of Bessie's pasture.

    FJ created a map of his N (1 <= N <= 1,000) pastures (conveniently numbered 1..N) that tells the parent P_i (1 <= P_i <= N) of each pasture except pasture 1, which has no parent.

    FJ has released his daily grazing schedule for the next M (1 <= M <= 1,000) days, so Bessie and Jonell are deciding where they should meet each day for gossip. On day k, Bessie is in pasture B_k (1 <= B_k <= N) and Jonell is in pasture J_k (1 <= J_k <= N).

    Given a map and schedule, help Bessie and Jonell find their meeting places.

    Consider, for example, the following farm layout:
    
                                Pasture      Parent Pasture
                 [1]           ---------    ----------------
                / |               1              ---
               /  |               2               1 
             [2] [3] [6]           3               1
             /        |           4               2
            /         |           5               8
          [4]        [8]  [9]      6               1
                    /             7               8
                   /              8               6
                 [5]     [7]       9               6
    
    Here are the meeting places that Bessie and Jonell would choose
    given a six day schedule of their initial grazing locations:
    
                  Bessie      Jonell       Meeting Place
                 --------    --------     ---------------
                     2           7               1
                     4           2               2
                     1           1               1
                     4           1               1
                     7           5               8
                     9           5               6

    输入输出格式

    输入格式:
    • Line 1: Two space-separated integers: N and M

    • Lines 2..N: Line i contains a single integer that describes the parent of pasture i: P_i

    • Lines N+1..N+M: Line k+N describes Bessie and Jonell's respective pastures with two space-separated integers: B_k and J_k
    输出格式:
    • Lines 1..M: Line j contains the meeting place Bessie and Jonell would use for line j+N of the input

    输入输出样例

    输入样例#1:
    9 6 
    1 
    1 
    2 
    8 
    1 
    8 
    6 
    6 
    2 7 
    4 2 
    3 3 
    4 1 
    7 5 
    9 5 
    
    输出样例#1:
    1 
    2 
    3 
    1 
    8 
    6 
    
    我们都在命运之湖上荡舟划桨,波浪起伏着而我们无法逃脱孤航。但是假使我们迷失了方向,波浪将指引我们穿越另一天的曙光。
  • 相关阅读:
    游戏UI框架设计(三) : 窗体的层级管理
    游戏UI框架设计(二) : 最简版本设计
    游戏UI框架设计(一) : 架构设计理论篇
    天启:如何从零开始建设数据中台? | 数智加速度04课回顾
    何夕:数据战略不仅是技术问题,更是业务和组织问题 | 数智加速度03课回顾
    才言:中台战略下,企业组织如何顺应商业变迁 | 数智加速度02回顾
    行在:数据中台的最终目的是给企业带来降本增效 | 数智加速度01课回顾
    腰部零售企业需要数据中台吗?
    硬核直播 | 全面解析数据中台,点燃「数智加速度」
    南京新百 × 奇点云 | 老字号百货购物中心运营的数智化转型破局
  • 原文地址:https://www.cnblogs.com/ruojisun/p/7436235.html
Copyright © 2011-2022 走看看