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 ...
随机推荐
- python2.7.5 安装pip 良心推荐,超级简单.
1 先安装setuptools 下载地址:https://pypi.python.org/pypi/setuptools#downloads 将下载后的tar文件解压,用CMD模式进入到解压后的文件所 ...
- ClearCase config_spec
1.使用分支前要在vob创建branch type,Config_Spec不能自动创建branch type: 2.如果可能,最好在以前确定的label上进行新的工作,避免维护复杂的config_s ...
- jquery +/-小样式
<script>部分 var num = 0; $(document).on('click','#add',function(){ _this = $(this); div = _this ...
- MySQL--如何快速对比数据
在MySQL运维中,研发同事想对比下两个不同实例上的数据并找出差异,除主键外还需要对比每一个字段,如何做呢? 第一种方案,写程序将两个实例上的每一行数据取出来进行对比,理论可行,但是对比时间较长. 第 ...
- Single-Pass Stereo Rendering for HoloLens——HoloLens的单程立体渲染
原文网站:https://docs.unity3d.com/Manual/SinglePassStereoRenderingHoloLens.html Single-Pass Stereo Rende ...
- wxpython发布还自己图标的程序
在py2exe安装脚本文件中,修改代码: setup( windows=[ { 'script': 'myapp.py', 'icon_resources': [(1, 'myicon.ico')] ...
- B 洛谷 P3604 美好的每一天 [莫队算法]
题目背景 时间限制3s,空间限制162MB 素晴らしき日々 我们的情人,不过是随便借个名字,用幻想吹出来的肥皂泡,把信拿去吧,你可以使假戏成真.我本来是无病呻吟,漫无目的的吐露爱情---现在这些漂泊不 ...
- Java获得系统的外网IP
关于如何获得系统外网IP?在网上找了好久,大多数解决方案都没法直接用,所以今天和大家分享一段获得外网IP的代码! import java.net.Inet4Address; import java.n ...
- PHP 5.6 微信上传临时素材的坑
/** * 上传素材 */ function add_material($url){ $access_token = wx_access_token(); $wx_url = "https: ...
- WPF字典集合类ObservableDictionary
WPF最核心的技术优势之一就是数据绑定.数据绑定,可以通过对数据的操作来更新界面. 数据绑定最经常用到的是ObservableCollection<T> 和 Dictionary<T ...