CodeForces - 796B 模拟
思路:模拟移动即可,如果球落入洞中停止移动。注意:有可能第一个位置就是洞!!
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 模拟的更多相关文章
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- Codeforces 709B 模拟
B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- 【codeforces 796B】Find The Bone
[题目链接]:http://codeforces.com/contest/796/problem/B [题意] 一开始骨头在1号位置; 然后有m个洞,给出洞的下标; 然后有k个交换操作; 如果骨头到洞 ...
- CodeForces - 404A(模拟题)
Valera and X Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- Codeforces 390A( 模拟题)
Inna and Alarm Clock Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces 452D [模拟][贪心]
题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...
- CodeForces - 864C-Bus-(模拟加油站问题)
https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...
- Codeforces 709C 模拟
C. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...
随机推荐
- Windows核心编程&错误处理
知识概要 (1) MAKELANGID Windows宏,用一个来主语言标识和从语言标识创建一个语言标识符 MAKELANGID(ushort usPrimaryLanguage, ushort us ...
- rpc-远程调用框架
简单框架编写 http://blog.csdn.net/u013177446/article/details/67638021 netty解决拆包粘包问题 http://www.cnblogs.com ...
- <select>设置multiple="multiple"属性后 下拉框全部展开了 不再是折叠的怎么回事
1 <select multiple="multiple" size="5"> <option>1</option> < ...
- Mysql了解及安装
1.数据库由两部分来构成的 打开一个连接工具,用工具给MySQL发送命令,实际上是给数据库当中的服务下的命令,在服务当中解析命令,最终将命令转化成对物理库上文件IO的操作. 所以数据库的安装位置有两个 ...
- 模型的元数据Meta -- Django从入门到精通系列教程
该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...
- Python selenium 一个节点两个关联input
HTML代码: 一个节点两个关联input 多出现于密码框 先需要模拟点击进入第一个input,才能激活第二个input. 代码: driver.find_element_by_name('Text ...
- 前端之基础css
一.anchor伪类,用于阅读文章. a:link(没有接触过的链接),用于链接常规状态 (末访问的链接)a:hover(鼠标放在链接上的状态) 用于产生视觉效果(已访问的链接)a:visited(访 ...
- spark头脑镜像
思考是一件有意思的事情.遇到问题,思考出结论,那么脑子里面的过程是什么呢,或者脑子里面是什么呢.我一直认为,这团团的里面是一个模糊的n维空间.理解一个复杂的系统.公式.算法,都要在这个n维空间里具象化 ...
- C# Sap Rfc 连接代码实例
根据不同的需求,安装不同位数的 Rfc SDK 1.构造 Sap Adress Information,且继承 IDestinationConfiguration public class SapAd ...
- python中的函数对象与闭包函数
函数对象 在python中,一切皆对象,函数也是对象 在python语言中,声明或定义一个函数时,使用语句: def func_name(arg1,arg2,...): func_suite 当执行流 ...