您的位置:首页 > 其它

NOIP2016提高组D1T1玩具谜题

2017-09-03 20:36 204 查看
D1T1 玩具谜题

地址:玩具谜题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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息