Codeforces Round #408 B. Find The Bone
来源:互联网 发布:淘宝赚钱 编辑:程序博客网 时间:2024/06/06 20:26
题目网址: Codeforces Round #408 B. Find The Bone
题意分析:
题意: 有n个杯子, 也有m个洞(被杯子盖着的), 且骨头初始放在第1个杯子内, zane会对两个杯子做k次交换的动作, 求最终骨头的位置.注意, 骨头掉进洞里就不会被交换了
思路: 模拟题, 掉进洞里, 骨头最终位置就是洞的那个位置, 没有掉进洞里, 就每次模拟交换杯子即可.
代码:
#include <iostream>#include <cstring>using namespace std;const int SIZE = 1e6+5;int cup[SIZE];int hole[SIZE];void swap(int &a, int &b){ int tmp = a; a = b; b = tmp;}int main(int argc, char const *argv[]){ int n, m, k; int tmp; int l, r; while (~scanf("%d %d %d", &n, &m, &k)) { memset(cup, 0, sizeof(cup)); memset(hole, 0, sizeof(hole)); cup[1] = 2; for (int i = 2; i <= n; ++i) { cup[i] = 1; } for (int i = 0; i < m; ++i) { scanf("%d", &tmp); hole[tmp] = 1; } bool flag = false; int ans = 1; if(hole[1] == 1) { flag = true; } for (int i = 0; i < k; ++i) { scanf("%d %d", &l, &r); if(!flag) { if(cup[l] == 2 && hole[r] == 1) { flag = true; ans = r; cup[l] = 1; } if(cup[r] == 2 && hole[l] == 1) { flag = true; ans = l; cup[r] = 1; } swap(cup[l], cup[r]); if(cup[r] == 2) ans = r; if(cup[l] == 2) ans = l; } } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- Codeforces Round #408 B. Find The Bone
- codeforces round#408(div.2) B. Find The Bone
- Codeforces Round #408 (Div. 2)-B. Find The Bone
- Codeforces Round #408 (Div. 2) B. Find The Bone
- Codeforces Round #408 (Div. 2) B.Find The Bone(模拟)
- Codeforces Round #408 (Div. 2) B. Find The Bone【模拟】水题~
- CodeForces 796B Find The Bone
- 【CodeForces 796B】Find The Bone
- 【Codeforces 796 B. Find The Bone】
- Find The Bone (Codeforces-796B)
- B. Find The Bone
- 796B Find The Bone
- cf find the bone
- codeforces 2B The least round way
- codeforces 2B The least round way
- codeforces 2B The least round way
- Educational Codeforces Round 7--B. The Time
- Educational Codeforces Round 7 B. The Time
- 动态规划(DP)的整理-Python描述
- Linux中vi命令
- 关于leveldb源码整理之二
- Codeforces Round #408 A. Buying A House
- 写在搬家前一天
- Codeforces Round #408 B. Find The Bone
- 基于LinkIt one的Arduino编程学习-按键操作
- Java集合源码学习(二)ArrayList分析
- 文章标题
- 只在本视图隐藏nav bar
- 未能加载文件或程序集“System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依
- 理解MVC模式和MVVM
- Hadoop搭建Hive异常处理
- java中的反转和换行相关问题