[luogu-1563]noip2016day1-T1 玩具谜题 题解
来源:互联网 发布:扁平化与金字塔 知乎 编辑:程序博客网 时间:2024/05/21 11:22
题目传送门
题意解析:题目就是给了你n个人组成的一个环,然后从第一个人开始移动的方案,让你找出最后到达的位置。
My opinion:看到题就知道是模拟,明显。(当然也是我noip唯一会做的题)这只不过是怎么来的问题罢了。
总结:
直接模拟便可。有一种简洁的方式不用这么多的if语句。 你可以发现如果一个人朝向是向外的,他的左右是相反的(废话,题目里都说了)
所以左右和朝向分别用0,1表示,如果左右和朝向的异或值决定了真实方向。
代码长是因为头文件:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<queue> #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=a;i>=n;i--) #define Clear(a,x) memset(a,x,sizeof(a)) #define ll long long #define INF 2000000000 #define eps 1e-8 using namespace std; ll read(){ ll x=0,f=1; char ch=getchar(); while (ch<'0'||ch>'9') f=ch=='-'?-1:f,ch=getchar(); while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; } const int maxn=100005,maxlen=15; int n,m; char s[maxn][maxlen]; int p[maxn]; int calc(int now){ if (now<=0) now+=n; if (now>n) now-=n; return now; } int main(){ n=read(),m=read(); rep(i,1,n){ p[i]=read(); scanf("%s",s[i]+1); } int now=1; rep(i,1,m){ int a=read(),l=read(); if (p[now]^a==0) now=calc(now-l); else now=calc(now+l); } cout<<s[now]+1<<endl; return 0; }
阅读全文
1 0
- [luogu-1563]noip2016day1-T1 玩具谜题 题解
- [NOIP] [模拟] NOIP2016Day1 玩具谜题
- NOIP2016 day1 T1 玩具谜题 toy 题解
- [luogu-1850]noip2016day1-T3 换教室 题解
- Noip2016day1 玩具迷题toy
- NOIP2016 T1 玩具谜题
- 【NOIP 2016 day1 T1 T3】玩具谜题,换教室——题解
- Luogu P1563 [NOIP2016]玩具谜题
- NOIP2016 day1 t1 玩具谜题
- [luogu-2678]noip2015day2-T1 跳石头 题解
- [noip2016]玩具谜题 题解
- Luogu P1563 [NOIp提高组2016]玩具谜题
- luogu P1563 玩具谜题(NOIP 2016TG)
- 玩具谜题 NOIP2016 提高组 Day1 T1
- Noip2016 Day1 T1 玩具谜题(字符串模拟)
- [luogu-2822]noip2016-day2-T1 组合数问题 题解
- NOIP2016Day1T1玩具谜题解题报告
- 【题解/2016提高】P1563 玩具谜题
- redis数据结构之一-简单动态字符串SDS
- 对于initialization failure 0x0000000c 的解决办法
- pthread_create()之前的属性设置
- 学习认识HTML基础入门Day01
- 编程思想之多线程与多进程(4)——C++中的多线程
- [luogu-1563]noip2016day1-T1 玩具谜题 题解
- php可变变量的用法
- Java中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
- H5定位指针矫正
- Java基础9:ArrayList和Array使用
- PHP注册页面生成验证码的实现
- JSONObject解析Boolean类型出现异常
- 线程,进程,协程
- html与js加载顺序