P1563 [NOIP2016 提高组] 玩具谜题(找规律,心要细,数学思维)

简介: P1563 [NOIP2016 提高组] 玩具谜题(找规律,心要细,数学思维)

Description of the topic



Xiaonan has a lovely set of toys, they have different occupations.


One day, these toy people hid Xiaonan's glasses. Xiaonan found the toys around a circle, some face inside, some face out of the circle. Here's the picture:

41c2bbe8de06ab467ea6413d10df2409.png


At this time, singersinger told Xiaonan a mystery: "The glasses are hidden in my left number 3rd toy person right number 11th toy person left number 22nd toy little person." ”


Xiaonan found that the toy in this puzzle is very critical, because the inside and outward toys are opposite to the left and right direction: face inside the circle of toys, its left side is clockwise direction, the right side is counterclockwise direction; And facing the toy person outside the circle, its left side is counterclockwise direction, the right side is clockwise direction.


Xiaonan struggled to identify the toy man, counting:


Singersinger faces inward, and the 33rd on the left is archerarcher.


Archer archer faced out, and the 11th on the right was thinkerthinker.


Thinkerthinker faces outwards, and the 22nd on the left is writwriter.


So the glasses are hidden here in writerwriter!


Although successfully recovered the glasses, but Xiaonan did not rest assured. If there were more toys to hide his glasses next time, or if the mystery was longer, he might not be able to find them. So Xiaonan wants you to write a program to help him solve similar puzzles. Such a puzzle can be described as:


There are nn toys in a circle, known for their occupation and orientation. Now the 11th toy man tells Xiaonan a mystery containing the mm instruction, wherein the zz instruction is shaped like "left/right number ss, a toy little man". You need to output these instructions in turn after arriving at the toy man's occupation.


Enter the format



The first line of the input contains two positive integers n, mn, m, representing the number of toy cubs and the number of instructions.


Next nn lines, each containing an integer and a string, gives the orientation and occupation of each toy person counterclockwise. Where 00 indicates an inner orientation ring and 11 indicates an outward orientation ring. Make sure that no other numbers appear. Strings are no longer than 1010 in length and consist only of lowercase letters, strings are not empty, and strings are two or two different. Integers and strings are separated by a space.


Next, line mm, where line ii contains two integer a_i, s_iai, si, for the second instruction. "If the a_i is 0ai, it means s_isi people to the left, and if a_i is 1ai to 1, it means to the right s_isi individuals." Guarantee that no other numbers will appear in the a_iai, 1 sle s_i < n1 ≤si<n.


The output format



Output a string that represents the occupation of the person who arrived after counting mm instructions, starting with the first person to read in.


A sample of the input and output



Enter #1 copy

7 3
0 singer
0 reader
0 mengbier 
1 thinker
1 archer
0 writer
1 mogician 
0 3
1 1
0 2


输出 #1复制

writer


输入 #2复制

10 10
1 C
0 r
0 P
1 d
1 e
1 m
1 t
1 y
1 u
0 V
1 7
1 1
1 4
0 5
0 3
0 1
1 6
1 2
0 8
0 4


输出 #2复制

y


说明/提示



【样例1说明】

这组数据就是【题目描述】 中提到的例子。


【子任务】

子任务会给出部分测试数据的特点。 如果你在解决题目中遇到了困难, 可以尝试只解决一部分测试数据。

每个测试点的数据规模及特点如下表:

6033e6e3ddd42b3974ebec4aa91a2ffe.png


其中一些简写的列意义如下:

• 全朝内: 若为“√”, 表示该测试点保证所有的玩具小人都朝向圈内;

全左数:若为“√”,表示该测试点保证所有的指令都向左数,即对任意的

1≤z≤m, a_i=01≤z≤m,ai=0;

s= 1s=1:若为“√”,表示该测试点保证所有的指令都只数1个,即对任意的

1≤z≤m,s_i=11≤z≤m,si=1;

职业长度为11 :若为“√”,表示该测试点保证所有玩具小人的职业一定是一个

长度为11的字符串。

题意分析就是要每一次的方向动都要进行更新,然后保证值为正,还有开数组大小要足够。


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+7;//如果发现运行对的但是就是过不了,考虑一下空间 
int main()
{
  int n,m;int k=1; 
  cin>>n>>m;
  int a[maxn];char b[maxn][11];
  for(int i=1;i<=n;i++)
  {
  cin>>a[i]>>b[i];      
  } 
  for(int i=1;i<=m;i++)
  {
    int x,y;
    cin>>x>>y;
    if(a[k]==0)
    {
      if(x==0)k=k-y;
      else k=k+y;
    }
  else
    {
      if(x==0)k=k+y;
      else k=k-y;
    }
    if(k<=0)k=k+n;
    if(k>n)k=k-n;
  }
  cout<<b[k]<<endl;
}
相关文章
Activiti7 驳回任务
Activiti7 驳回任务
2183 0
|
开发框架 JavaScript 小程序
uni-app——如何阻止事件冒泡
uni-app——如何阻止事件冒泡
1107 0
|
存储 关系型数据库 MySQL
Nacos 2.0.3和Nacos 2.2.3版本
Nacos 2.0.3和Nacos 2.2.3版本
1456 1
|
前端开发 JavaScript 定位技术
folium底图本地化处理
folium底图本地化处理
1011 0
|
JSON 网络协议 安全
阿里云公共DNS安全传输服务介绍(DoH/DoT)
传统的DNS查询和应答采用大都采用UDP明文传输,存在网络监听、DNS劫持、中间设备干扰的风险。为了应对以上挑战,阿里公共DNS对外提供支持DoH/DoT的云服务,为广大的互联网用户提供快速、稳定和安全的DNS解析,欢迎大家使用!
阿里云公共DNS安全传输服务介绍(DoH/DoT)
|
11月前
|
安全 网络安全 调度
游戏盾接入指南:原理、功能与多平台集成方案
游戏盾是一种面向游戏行业的专业网络安全防护解决方案,专门针对DDoS攻击、CC攻击等网络安全威胁提供全方位保护。它通过分布式防护节点、智能调度系统和加密通信隧道三大核心技术,为游戏业务建立坚不可摧的安全防线。
675 1
|
5月前
|
人工智能 搜索推荐 算法
3个AI工具27篇GEO文章实测:60/40法则与3步补刀流程
本文实测ChatGPT、Claude、豆包生成GEO文章表现:平均综合可用分仅67/100,假数据率48%、同质化率30%、平台事实错误率30%。提出「60/40法则」——AI完成60%框架结构,40%关键事实需人工补刀,并给出三步法:补真实数据、补真实案例、补产品细节,助质量从60分跃升至90分。
484 1
|
6月前
|
弹性计算 安全 数据库
阿里云办公安全平台SASE完全对接指南:零信任架构下的企业安全接入实践
本文是一篇全面深入的阿里云办公安全平台SASE(Secure Access Service Edge)对接使用指南。文章从零信任安全理念出发,系统介绍了SASE的核心概念与产品架构,详细阐述了从开通服务、配置身份源(支持IDaaS、LDAP、钉钉、企业微信等多种对接方式)、添加办公应用到配置零信任策略的全流程操作。重点讲解了SASE如何与阿里云IDaaS实现单点登录SSO、如何安全对接云上ECS、RDS数据库等资产、如何配置终端安全基线实现动态访问控制,以及如何进行办公数据防泄漏保护。文中还提供了Python SDK集成代码示例,帮助开发者实现自动化管理。文章最后通过问答形式总结了常见问题与解
|
9月前
|
Web App开发 人工智能
火语言 RPA:模拟真人操作 —— 微博超话签到、发布互动贴与浏览全流程案例
本案例基于火语言RPA,自动化完成微博超话签到、发帖互动及10次滚动浏览,精准模拟真人行为。支持指定Chrome路径与用户配置,智能判断签到弹窗、条件执行操作,并自动关闭浏览器释放资源,有效提升账号活跃度。
668 2
|
11月前
|
人工智能 监控 API
分布式智能崛起后,我们终于知道 AI调度官 负责什么了
2026年,AI从云端巨兽蜕变为亿级边缘智能体,“AI调度官”应运而生——不再写提示词,而是设计交互协议、调控算力资源、熔断群体风险、注入人类价值观。他们是分布式智能时代的“立法者”与“守夜人”,掌控人机共生新秩序。(239字)
516 6