NOIP2016提高组D1T1玩具谜题
2017-09-03 20:36
204 查看
D1T1 玩具谜题
地址:玩具谜题Vijos
题解:
这道题因为是个圈,所以我们可以直接用取模O(1)模拟每次的位置变化,总时间就只用O(n),n最大只有100000可以轻松解决。但要注意编号变化的方向和每个人的朝向还有传递的方向。因为朝内人的左边和朝外人的右边是相同的方向,我们可以用异或来确定方向,不过每次都分类讨论也是可以的。
代码:
地址:玩具谜题Vijos
题解:
这道题因为是个圈,所以我们可以直接用取模O(1)模拟每次的位置变化,总时间就只用O(n),n最大只有100000可以轻松解决。但要注意编号变化的方向和每个人的朝向还有传递的方向。因为朝内人的左边和朝外人的右边是相同的方向,我们可以用异或来确定方向,不过每次都分类讨论也是可以的。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define ll long long #define N 100005 inline int read(){ int x = 0,f = 1;char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = x*10+ch-'0'; ch = getchar();} return x*f; } string name ; int Scarlet ; int n,m; int ans = 0; int main(){ n = read(); m = read(); for(int i = 0;i < n;i++){ Scarlet[i] = read(); cin >> name[i]; } for(int i = 1;i <= m;i++){ int scarlet = read(); int Remililia = read(); if(scarlet ^ Scarlet[ans]){ ans = (ans + Remililia) % n; } else{ ans = (ans - Remililia + n) % n; } } cout << name[ans] << endl; return 0; }
相关文章推荐
- 【NOIP2016】洛谷1563 玩具谜题
- 洛谷 P1563 玩具谜题
- NOIP2016玩具谜题(洛谷1563)
- noip2016d1t1 玩具谜题
- [Noip2017][Day 1][T1]玩具谜题(toy.cpp)
- 洛谷Oj-P1563 玩具谜题-模拟
- 【NOIP2016提高组复赛】玩具谜题
- 【模拟】[NOIP2016&2015]玩具谜题&神奇的幻方
- NOIP2016Day1T1-玩具谜题
- C++学习日记(玩具谜题AC,)
- 玩具谜题(NOIP2016提高组day1第1题)
- 【NOIP】玩具谜题
- 【题解/2016提高】P1563 玩具谜题
- [NOIP2016提高组]玩具谜题
- 【模拟】玩具谜题 luogu-1563
- 【NOIP 2016 提高组】玩具谜题
- NOIP2016 day1 t1 玩具谜题
- noip2016D1T1 玩具谜题
- NOIP2016 Day1 玩具谜题
- 玩具谜题