思路:模拟移动即可,如果球落入洞中停止移动。注意:有可能第一个位置就是洞!!

AC代码

#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 1e6 + 5;
int hole[maxn], pos[maxn];
int main() {
	int n, m, k;
	while(scanf("%d%d%d", &n, &m, &k) == 3) {
		memset(hole, 0, sizeof(hole));
		memset(pos, 0, sizeof(pos));
		int h;
		for(int i = 0; i < m; ++i) {
			scanf("%d", &h);
			hole[h] = 1;
		}
		pos[1] = 1;
		int ans = 1;
		int x, y, flag = 0;
		if(hole[1]) flag = 1;
		for(int i = 0; i < k; ++i) {
			scanf("%d%d", &x, &y);
			if(flag) continue;
			if(pos[x]) {
				pos[x] = 0;
				pos[y] = 1;
				ans = y;
			}
			else if(pos[y]){
				pos[y] = 0;
				pos[x] = 1;
				ans = x;
			}
			if(hole[ans]) flag = 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}

如有不当之处欢迎指出!

CodeForces - 796B 模拟的更多相关文章

  1. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  2. CodeForces - 404B(模拟题)

    Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Sta ...

  3. Codeforces 709B 模拟

    B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  4. 【codeforces 796B】Find The Bone

    [题目链接]:http://codeforces.com/contest/796/problem/B [题意] 一开始骨头在1号位置; 然后有m个洞,给出洞的下标; 然后有k个交换操作; 如果骨头到洞 ...

  5. CodeForces - 404A(模拟题)

    Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit ...

  6. Codeforces 390A( 模拟题)

    Inna and Alarm Clock Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64 ...

  7. Codeforces 452D [模拟][贪心]

    题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...

  8. CodeForces - 864C-Bus-(模拟加油站问题)

    https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...

  9. Codeforces 709C 模拟

    C. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...

随机推荐

  1. js_2_json

    js如何使用json? json.stringify(需要序列化对象)  // 序列化 josn.parse(已经序列化对象)       // 反序列化

  2. 流API--流的基础知识

    流接口--BaseStream接口 流API定义了几个流接口,这些接口包含在java.util.stream中.BaseStream是基础接口,它定义了所有流都可以使用的基本功能.我们来看一下源码: ...

  3. 微信支付JSAPI公众号支付授权目录

    详情 http://yangjunwei.com/a/1815.html

  4. nc简单应用

    传输本地文件test到172.19.135.12: 172.19.135.12接收端 nc -l   1234 > test 本地为  发送端 nc  172.19.135.12  1234 & ...

  5. struts 中自定义action访问方法

    struts中action类继承了ActionSupport  默认实现了execute()方法 struts.xml配置文件中 然后可以配置如下映射: <package name =" ...

  6. linux下安装pip

    1.pip下载安装 wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d ...

  7. js函数知识

    1.函数基本知识 通过函数可以封装任意条语句,在任何地方调用,js中用function关键字来声明, //基本格式,函数名,传递参数,代码块 function functionName(arg0,ar ...

  8. 08_Python编码与解码

    一.编码的由来 因为计算机只能处理010101二进制数据,如果要处理文本,图像,视频等,需要我们把数据转换成01010二进制格式才能被计算机处理 最先出现的是ASCII,用8位一个字节来表示,成为单字 ...

  9. 使用JavaScript实现机器学习和神经学网络

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 下载heaton-javascript-ml.zip - 45.1 KB 基本介绍 在本文中,你会对如何使用JavaScript实现机器学习这个 ...

  10. LANMP系列教程之MySQL编译安装CentOS7环境

      以MySQL5.5.33版本为例 1.准备工作: 1.首先准备好源代码包 2.并且确保已安装好 "开发工具" 包组和cmake编译工具 3.确保安装好ncurses-devel ...