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 ...
随机推荐
- 创建md5摘要,规则是:按参数名称a-z排序,遇到空值的参数不参加签名。
/** * 创建md5摘要,规则是:按参数名称a-z排序,遇到空值的参数不参加签名. */ private function createSign($parameters,$key) { $signP ...
- 企业级分布式存储应用与实战FastDFS实现
FASTDFS是什么 FastDFS是由国人余庆所开发,其项目地址:https://github.com/happyfish100 FastDFS是一个轻量级的开源分布式文件系统,主要解决了大容量的文 ...
- ATS 分级缓存
理解缓存分级cache hierarchies 缓存分级是由彼此能够相互通信的各级缓存组成的,ATS支持几种类型的缓存分级.所有的缓存分级都有父子缓存概念. 父缓存位于缓存分级的较高级别,ATS能将请 ...
- Java解决CSRF问题
项目地址: https://github.com/morethink/web-security-csrf CSRF是什么? CSRF(Cross-site request forgery),中文名称: ...
- SQL作业二
目的:通过加载chinook_db文件来把数据导入到sqllite,根据题目的要求进行查询 1.sql语句的基本语法 2.join多表查询的用法 3.group by分组的用法 4.order by排 ...
- 洛谷 [P3973] 线性代数
最大权闭合子图,神题 这不是线性代数,这是网络流. 我们看见这是一堆矩阵的运算,而且最后变成了一个数,那么我们就想到,把这个矩阵乘法的过程用具体的数字推出来 我们发现,a是一个01矩阵,然后其实就可以 ...
- CF 291E. Tree-String Problem [dfs kmp trie图优化]
CF291E 题意:一棵树,每条边上有一些字符,求目标串出现了多少次 直接求目标串的fail然后一边dfs一边跑kmp 然后就被特殊数据卡到\(O(n^2)\)了... 因为这样kmp复杂度分析的基础 ...
- 游戏2048源代码 - C语言控制台界面版
一.游戏介绍 <2048>是最近比较流行的一款数字游戏.原版2048首先在github上发布,原作者是Gabriele Cirulli.它是基于<1024>和<小3传奇& ...
- selenium headlesschrome下设置最大窗口模式
做微博登录的时候,用selenium的chrome界面模式,可以用下面方式显示最大窗口: from selenium.webdriver.chrome.options import Options c ...
- python学习资料链接
1.入门与量化:https://www.v2ex.com/t/257297