被坑水题——Codeforces Round #408 (Div. 2)
来源:互联网 发布:2017中国大数据50强 编辑:程序博客网 时间:2024/06/05 07:22
B. Find The Bone
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.
//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <cstring>#include <cmath>//#include <cctype>#include <queue>#include <vector>#include <string>#include <stack>#include <set>#include <map>//#include <sstream>#include <iostream>#include <bitset>#include <algorithm>using namespace std;#define MP make_pair#define PB push_back#define mst(a,b) memset((a),(b),sizeof(a))#define TEST cout<<"*************************"<<endl#define rep(s,n,up) for(int i = (s); i < (n); i+=(up))#define per(n,e,down) for(int i = (n); i >= (e); i-=(down))#define rep1(s,n,up) for(int j = (s); j < (n); j+=(up))#define per1(n,e,down) for(int j = (n); j >= (e); j-=(down))typedef long long LL;typedef unsigned long long uLL;typedef pair<int, int> Pii;typedef vector<int> Vi;typedef vector<Pii> Vii;const int inf = 0x3f3f3f3f;const LL INF = (1uLL << 63) - 1;const double Pi = acos(-1.0);const int maxn = (1 << 16) + 7;const uLL Hashmod = 29050993;const double esp=1e-6;//#define localbool hole[1000005];int main() {#ifdef local freopen("input.txt", "r", stdin); //freopen("output.txt","w",stdout);#endif //ios::sync_with_stdio(0); //cin.tie(); LL n,m,k; mst(hole,0); scanf("%lld%lld%lld",&n,&m,&k); while(m--){ LL i; scanf("%lld",&i); hole[i]=1; } LL s,e,bone=1; while(k--){ scanf("%lld%lld",&s,&e); if(!hole[bone]&&s==bone) bone=e; } printf("%lld\n",bone); return 0;}
后来看了CF上的MY SUBMISSIONS-SOURCE才知道自己考虑不佳//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <cstdio>#include <cstring>#include <cmath>//#include <cctype>#include <queue>#include <vector>#include <string>#include <stack>#include <set>#include <map>//#include <sstream>#include <iostream>#include <bitset>#include <algorithm>using namespace std;#define MP make_pair#define PB push_back#define mst(a,b) memset((a),(b),sizeof(a))#define TEST cout<<"*************************"<<endl#define rep(s,n,up) for(int i = (s); i < (n); i+=(up))#define per(n,e,down) for(int i = (n); i >= (e); i-=(down))#define rep1(s,n,up) for(int j = (s); j < (n); j+=(up))#define per1(n,e,down) for(int j = (n); j >= (e); j-=(down))typedef long long LL;typedef unsigned long long uLL;typedef pair<int, int> Pii;typedef vector<int> Vi;typedef vector<Pii> Vii;const int inf = 0x3f3f3f3f;const LL INF = (1uLL << 63) - 1;const double Pi = acos(-1.0);const int maxn = (1 << 16) + 7;const uLL Hashmod = 29050993;const double esp=1e-6;//#define localbool hole[1000005];int main() {#ifdef local freopen("input.txt", "r", stdin); //freopen("output.txt","w",stdout);#endif //ios::sync_with_stdio(0); //cin.tie(); int n,m,k; mst(hole,0); scanf("%d%d%d",&n,&m,&k); while(m--){ int i; scanf("%d",&i); hole[i]=1; } int s,e,bone=1; while(k--){ scanf("%d%d",&s,&e); if(!hole[bone]) { if(s==bone) bone=e; else if(e==bone) bone=s; } } printf("%d\n",bone); return 0;}
ACM路上的渣渣将第一次BLOG献给被坑水题 - 被坑水题——Codeforces Round #408 (Div. 2)
- Codeforces Round #408 (Div. 2)
- Codeforces Round #408 (Div. 2) A
- Codeforces Round #408 (Div. 2) C
- Codeforces Round #408(Div.2)
- Codeforces Round #408 (Div. 2) E
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #156 (Div. 2)——B
- Codeforces Round #151 (Div. 2)——B
- Codeforces Round #152 (Div. 2)——B
- Codeforces Round #149 (Div. 2)——B
- Codeforces Round #146 (Div. 2)——B
- Codeforces Round #144 (Div. 2)——B
- Codeforces Round #142 (Div. 2)——B
- Codeforces Round #157 (Div. 2)——B
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #141 (Div. 2)——B
- Codeforces Round #140 (Div. 2)——B
- CentOS 7下 docker pull加速 亲测可用
- 缺少动态连接库.so--cannot open shared object file: No such file or directory
- afx.h与window.h
- yum 安装启动httpd
- ubuntn 16.04.2下caffee的安装教程
- 被坑水题——Codeforces Round #408 (Div. 2)
- 用octopress搭建博客时遇到的一些问题
- 设计模式_装饰模式概述和使用
- [网络流] 网络流(22/24)题题解集合
- 指针和数组的区别 (从下标运算符[ ]看)
- ARP协议和RARP协议
- celery 分布式框架详解
- cz1-tomcat项目导包错误导致的项目加载失败
- Cookie Session
程序博客网,程序员的互联网技术博客家园。csdn论坛精品 msdn技术资料都在这里