zoukankan      html  css  js  c++  java
  • Codeforces Round #408 (Div. 2) B

    Description

    Zane the wizard is going to perform a magic show shuffling the cups.

    There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.

    The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = ui and x = vi. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.

    Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5at any moment during the operation.

    Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.

    Input

    The first line contains three integers nm, and k (2 ≤ n ≤ 1061 ≤ m ≤ n1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

    The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there is a hole on the table.

    Each of the next k lines contains two integers ui and vi (1 ≤ ui, vi ≤ nui ≠ vi) — the positions of the cups to be swapped.

    Output

    Print one integer — the final position along the x-axis of the bone.

    Examples
    input
    7 3 4
    3 4 6
    1 2
    2 5
    5 7
    7 1
    output
    1
    input
    5 1 2
    2
    1 2
    2 4
    output
    2
    Note

    In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively.

    In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.

    题意:骨头在第一个位置,有hi个洞,我们进行移动操作,如果骨头掉入洞里就输出洞的位置,否则按照移动的最后结果输出

    解法:首先骨头在第一个位置,如果第一个位置有洞则直接输出,否则模拟移动操作,当然有些移动操作对结果没有影响

    直到进洞或者移动结束

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 map<int,int>q;
     5 int n,m,k;
     6 int main()
     7 {
     8     std::ios::sync_with_stdio(false);
     9     cin>>n>>m>>k;
    10     for(int i=1;i<=m;i++)
    11     {
    12         int num;
    13         cin>>num;
    14         q[num]=1;
    15     }
    16     if(q[1])
    17     {
    18         cout<<"1"<<endl;
    19         return 0;
    20     }
    21     int ans=1;
    22     for(int i=1;i<=k;i++)
    23     {
    24         int v,u;
    25         cin>>v>>u;
    26         if(v!=ans&&u!=ans) continue;
    27         if(q[ans])
    28         {
    29             cout<<ans<<endl;
    30             return 0;
    31         }
    32         else if(v==ans)
    33         {
    34             swap(v,u);
    35             ans=v;
    36         }
    37         else if(u==ans)
    38         {
    39             swap(v,u);
    40             ans=u;
    41         }
    42     }
    43     cout<<ans<<endl;
    44     return 0;
    45 }
  • 相关阅读:
    Win(Phone)10开发第(7)弹,Extended Execution
    Win(Phone)10开发第(5)弹,本地媒体服务器的一些注意事项
    Win(Phone)10开发第(4)弹,HTTP 实时流播放 m3u8
    Win(Phone)10开发第(3)弹,简单的Demo程序网络请求json解析列表显示
    Win(Phone)10开发第(2)弹,导出APPX包并签名部署
    Win(Phone)10开发第(1)弹,桌面和手机的扩展API,还我后退键
    WP8里dll类库(SDK)实现多语言多主题
    Windows Phone中解决多模块多程序集之间相互循环引用的问题一种思路
    在继承中子类自动实现单例模式
    ansible---基础
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6701558.html
Copyright © 2011-2022 走看看