zoukankan      html  css  js  c++  java
  • CF-796B

    B. Find The Bone
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 = 5 at 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 ≤ 106, 1 ≤ 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.

    题意:

    有n个杯子,m个杯子底下有洞,将骨头交换k次,遇到洞就会掉下去不动,求最后骨头的位置。

    注意交换的两个位置是不分先后的。

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main(){
     5     ios::sync_with_stdio(false);
     6     int h[1000010];
     7     int n,m,k,t,s,flag=0,ans=1;
     8     cin>>n>>m>>k;
     9     //scanf("%d%d%d",&n,&m,&k);
    10     memset(h,0,sizeof(h));
    11     for(int i=0;i<m;i++){
    12         cin>>t;
    13         //scanf("%d",&t);
    14         h[t]=1;
    15     }
    16     if(h[1]){
    17         flag=1;
    18     }
    19     for(int i=0;i<k;i++){
    20         cin>>t>>s;
    21         //scanf("%d%d",&t,&s);
    22         if(!h[t]&&ans==t){
    23             ans=s;
    24         }
    25         else if(!h[s]&&ans==s){
    26             ans=t;
    27         }
    28     }
    29     cout<<ans<<endl;
    30     return 0;
    31 } 
  • 相关阅读:
    SparkR初体验2.0
    R语言数据集合并、数据增减、不等长合并
    采坑复盘:logging日志能用封装后的函数来打日志,发现filename一直显示封装logging函数的方法所在的文件名
    flask实战-个人博客-编写博客前台
    flask实战-个人博客-电子邮件支持
    linux虚拟机获取不到ip的解决方法 --
    flask实战-个人博客-视图函数
    flask实战-个人博客-表单
    flask实战-个人博客-模板 --
    flask实战-个人博客-数据库-生成虚拟数据 --
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/6798499.html
Copyright © 2011-2022 走看看