B. Find The Bone
来源:互联网 发布:李涛疯狂淘宝 传销 编辑:程序博客网 时间:2024/06/05 14:33
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.
The first line contains three integers n, m, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n, 1 ≤ 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 ≤ n, ui ≠ vi) — the positions of the cups to be swapped.
Print one integer — the final position along the x-axis of the bone.
7 3 43 4 61 22 55 77 1
1
5 1 221 22 4
2
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.
题解:挺水的,但是一直WA,简直要哭,第一个坑是第一个cup就有可能有洞,第二个坑是,判断条件稍微长点或者多个分支就会Time Limit,真是惨痛的教训。
代码如下:
//// main.cpp// B. Find The Bone//// Created by 徐智豪 on 2017/4/18.// Copyright © 2017年 徐智豪. All rights reserved.//#include <iostream>#include <stdio.h>using namespace std;int n,m,k;bool h[1000015]={false};int bones=1;int main(int argc, const char * argv[]) { cin>>n>>m>>k; int holes; for(int i=1;i<=m;i++) { cin>>holes; h[holes]=1; } int u,v; bool flag=0; for(int i=0;i<k;i++) { scanf("%d%d",&u,&v); if(h[1]==true) { bones=1; flag=true; } if((bones==u||bones==v)&&!flag) bones=u+v-bones; if(h[bones]==true) flag=true; } cout<<bones<<endl; return 0;}
- B. Find The Bone
- 796B Find The Bone
- CodeForces 796B Find The Bone
- 【CodeForces 796B】Find The Bone
- 【Codeforces 796 B. Find The Bone】
- Codeforces Round #408 B. Find The Bone
- Find The Bone (Codeforces-796B)
- codeforces round#408(div.2) B. Find The Bone
- Codeforces Round #408 (Div. 2)-B. Find The Bone
- Codeforces Round #408 (Div. 2) B. Find The Bone
- Codeforces Round #408 (Div. 2) B.Find The Bone(模拟)
- cf find the bone
- Codeforces Round #408 (Div. 2) B. Find The Bone【模拟】水题~
- 0519 G2n#W2B-C Find The Bone
- UVA - 10921 - Problem B - Find the Telephone
- NYOJ B. Bone Collector
- Tempter of the Bone
- Tempter of the Bone
- 图解财务 系列电子书
- gradle 学习资料汇总
- 欢迎使用CSDN-markdown编辑器
- 熄灯之后的学习——再读《MySQL必知必会》(6)|| 数据过滤
- gradle android 目录结构
- B. Find The Bone
- macbook 配置 Maven
- LeetCode Intersetion of two array
- C#FTP帮助 类
- 依赖传递
- gradle 打印依赖树
- gradle 查看库本地存储地址
- android基础知识---语言切换
- gradle 包装器