796B Find The Bone
2 seconds
256 megabytes
standard input
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.
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 4
3 4 6
1 2
2 5
5 7
7 1
1
5 1 2
2
1 2
2 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.
题意:给你n个杯子标号为(1~n),有m个杯子有洞,有k次操作,
每次操作交换编号为u和编号为v的杯子,如果这个杯子 有洞,骨头就会掉下去,
初始骨头在位置1,现在问你k此操作以后骨头在哪里
解析:标记洞编号,每次交换前判断骨头是否掉入洞中,
如果交换的两个杯子中没有骨头,骨头位置没有变,不用处理
如果交换的两个杯子中有骨头,在 ui 中,并且骨头未掉入洞中, 骨头位置变化到 vi 中
在 vi 中,并且骨头未掉入洞中, 骨头位置变换到 ui 中
重复 K 次操作,最后找到 骨头的位置
另:用cin cout 可能会超时,较大数据用scanf(); printf();
#include <iostream>
#include <cstdio>
using namespace std;
const int M = 1e6 +;
int holes[M];
int main(){
int n, m, k;
scanf("%d%d%d",&n,&m,&k);
//cin >> n >> m >> k;
int stone = ;
for(int i = ; i < m; i++){
int hol;
//cin >. hol;
scanf("%d",&hol);
holes[hol] ++;
}
for(int i = ; i < k; i++){
int ui, vi;
//cin >> ui >> vi;
scanf("%d%d",&ui,&vi);
if(ui == stone && holes[ui] != ){
stone = vi;
}
else if(vi == stone && holes[vi] != ){
stone = ui;
}
}
//cout << stone << endl;
printf("%d",stone);
}
796B Find The Bone的更多相关文章
- codeforces 796A-D
决定在 codeforces 练题啦,决定每个比赛刷前四道...太难就算了 796A Buying A House 题意:给出x轴上的n 个点,每个点有个权值,问离m 点最近的权值小于等于k 的点离m ...
- 【codeforces 796B】Find The Bone
[题目链接]:http://codeforces.com/contest/796/problem/B [题意] 一开始骨头在1号位置; 然后有m个洞,给出洞的下标; 然后有k个交换操作; 如果骨头到洞 ...
- 玩儿转物联网IoT - 在Beagle Bone Black上运行node.js 程序
物联网(IoT)技术方兴未艾,智能手环,智能血压计,智能眼镜甚至智能鞋垫都开始进入我们的生活,各种智能设备层出不穷,世界已经到了一个"人有多大胆,地有多大产"的时代,不玩儿点物联网 ...
- Tempter of the Bone
Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- hdu–2369 Bone Collector II(01背包变形题)
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...
- hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 2602 Bone Collector WA谁来帮忙找找错
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
随机推荐
- zabbix 邮件报警 监控mysql主从
1)设置邮件模板及邮件服务器 邮箱密码记得写授权密码 2)配置接受报警的邮箱 3)添加报警触发器 配置邮箱服务器 yum -y install mailx yum -y install sendmai ...
- ADO.Net 数据库修改
数据库的修改方法和增加一样,只是把增加语句换成了修改语句,后面执行语句是相同的 首先也是需要获取并接收输入的要修改的哪个数据以及修改后的数据 代码演示: using System; using Sys ...
- 解题2(IpIsSameSubNet)
题目描述 子网掩码是用来判断任意两台计算机的IP地址是否属于同一子网络的根据.子网掩码与IP地址结构相同,是32位二进制数,其中网络号部分全为“1”和主机号部分全为“0”.利用子网掩码可以判断两台主机 ...
- C语言标准io函数总结
转自:http://blog.csdn.net/sun_top/article/details/4235992本来是在vscode上用markdown排好版的,结果复制到这上面就变了形,无奈. 函数列 ...
- springboot jpa sql查询与传值
public interface ARepository extends PagingAndSortingRepository<A, APK>, JpaSpecificationExecu ...
- UltraEdit窗口布局重新设置
解决办法:工具栏中的视图-->环境-->左边小框里选择“编程员”,再点选择环境 转载:https://blog.csdn.net/u011650048/article/details/18 ...
- MVC中html编码与否
MVCHtmlString可以不进行编码. 例子:string s=‘<a style="color:red">链接</a>’: 1.@s,直接输出< ...
- 八 xml模块
xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单,不过,古时候,在json还没诞生的黑暗年代,大家只能选择用xml呀,至今很多传统公司如金融行业的很多系统的 ...
- leetcode 数组类型题
// ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <Windows.h& ...
- Python_变量命名
Python的变量命名 变量的命名的原则一直都是我这种小白的头疼事,好几条,根本记不住...... 为了解决大家的头疼问题,今天想出来一个好办法,那就是:身边常备头疼片.......(哈哈哈,开玩笑的 ...