模拟——玩具谜题
来源:互联网 发布:怎么开一个淘宝店 编辑:程序博客网 时间:2024/05/08 01:06
题目来源
洛谷P1563玩具谜题
https://www.luogu.org/problem/show?pid=1563
思路
结构体存小人信息(名字toy[i].na+方向toy[i].dir[朝圈外1 朝圈内-1])
pos表示当前位置
输入步骤(方向d[向左-1 向右1]+步数s)
则pos=(pos-d*toy[pos].dir*s)
(
向左&&朝外==向右&&朝内==逆时针 => pos=pos-s(mod n&&pos>0)
向左&&朝内==向右&&朝外==顺时针 => pos=pos+s(mod n&&pos>0)
)
代码(C++)
#include <iostream>#include <cstdio>#include <string>using namespace std;int n,m,pos=1,d,s;struct p{int dir;string na;}toy[100010];int main(){ cin>>n>>m; for(int i=1;i<=n;i++) { cin>>toy[i].dir>>toy[i].na; if(toy[i].dir==0) toy[i].dir=-1; } for(int i=1;i<=m;i++) { cin>>d>>s; s=s%n; if(d==0) d=-1; if(d*toy[pos].dir==-1) { pos+=s; pos%=n; } else { pos=pos-s; pos%=n; pos+=n; pos%=n; } if(pos==0) pos=n; } cout<<toy[pos].na; return 0;}
阅读全文
1 0
- 模拟——玩具谜题
- 玩具装箱(noip冲刺模拟题——DP)
- [NOIP] [模拟] NOIP2016Day1 玩具谜题
- 洛谷1563(NOIP2016)[玩具谜题]--模拟
- Noip2016 Day1 T1 玩具谜题(字符串模拟)
- UOJ 260(模拟)(玩具谜题)
- [NOIP模拟][好题]分玩具
- [NOIP2016] 玩具谜题
- 玩具谜题
- 玩具谜题(NOIP2016)
- noip2016d1t1 玩具谜题
- 玩具谜题
- noip2016D1T1 玩具谜题
- 【NOIP】玩具谜题
- 玩具谜题
- 【noip2016】玩具谜题
- 模拟(玩具谜题NOIP 2016 提高组 Day 1 第一题vijos2003)
- [NOIP2017模拟]分玩具
- JAVA IO详解(转)
- window10下安装TensorFlow
- Xilinx SDK中指定变量的物理位置
- ZYNQ Linux开发——以太网配置
- java线程通信
- 模拟——玩具谜题
- dotnet core 做微信公众号开发时遇到的问题1
- C++--vector<>容器,List<>链表,map<>容器的用法
- 让你奶奶轻松搞懂Naive Bayes的理论与实践
- QDockWidget
- 伤情最是晚凉天
- vue-cli构建vue项目
- 请写一个方法计算s=a+aa+aaa+aaaa+aa...a,其中a取值范围是[1-9]
- Spring Session + Redis实现分布式Session共享