2556. [NOIP2016] toy puzzle, 2556noip2016

Source: Internet
Author: User

2556. [NOIP2016] toy puzzle, 2556noip2016
[Description]


Xiaonan has a set of cute little toys, which have different occupations. One day, these little toys hid Nan's glasses. Xiaonan found that the toys and children were circled in a circle, and some of them looked inside and outside China. For example:


At this time, singer told Xiaonan a puzzle: "glasses are hidden in the left of the first 3rd toy people on the right, 1st toy people on the left, and 2nd toy people on the left ."

Xiao Nan found that the orientation of the little toys in this puzzle is very critical, because the left and right directions of the little toys inside and outside are opposite: the little toys inside and outside the circle, and the left side is clockwise, the right side is a counter-clockwise direction, while the left side is a counter-clockwise direction for the out-of-the-box toys.

Xiaonan, while struggling to identify the little toys, was counting:

"Singer is in the inner direction, and 3rd on the left is archer.

"Archer faces outward, and the number of 1st on the right is thinker.

"The number of thinker on the left is 2nd writer.

"So the glasses are hidden in writer !"

Although the glasses were successfully retrieved, Xiaonan was not at ease. If more little toys hide his glasses or the length of the puzzle is longer, he may not be able to find the glasses. So Xiaonan wants you to write a program to help him solve similar puzzles. Such puzzles can be described as follows:

There are n toys shortlisted in a circle, and they know their profession and orientation. Now, 1st little toys tell little nan a puzzle containing m instructions, in which the I directive is like "left/right number Si little toys ". You need to output the occupation of the little toys that arrive after the instructions are completed by the number of times.



[Input format]


Read data from a file.

The first line contains two positive integers n and m, indicating the number of little toys and the number of instructions.

In the next n rows, each line contains an integer and a string, which provides the orientation and occupation of each villain in a counter-clockwise order. 0 indicates orientation inside the circle, and 1 indicates orientation outside the circle. Make sure that no other number is displayed. The string cannot exceed 10 characters in length and is composed of only lowercase letters. The string is not empty and is different from each other. Use a space to separate integers from strings.

Next, the m line contains two integers, namely, the I command. If ai is set to 0, it indicates the number of Si people to the left; If ai is set to 1, it indicates the number of Si people to the right. Ensure that no other number appears in the ai, 1 <si <n.


[Output format]


Output to the file.

Output a string that indicates the occupation of the villain that arrives after the first entry of the villain based on the number of m commands.


[Example 1 input]
7 30 singer0 reader0 mengbier1 thinker1 archer0 writer1 mogician0 31 10 2
[Example 1 Output]
writer
[Example 1 prompt]

This set of data is the example mentioned in [description.

[Example 2 input]
10 101 c0 r0 p1 d1 e1 m1 t1 y1 u0 v1 71 11 40 50 30 11 61 20 80 4
[Example 2 output]
y
Tip]


The subtask will show the characteristics of some test data. If you encounter difficulties in solving the problem, you can try to solve only a part of the test data.

The data scale and characteristics of each test point are as follows:


Some abbreviated columns have the following meanings:

· Quanchao: If it is "√", it indicates that the test point ensures that all the little toys are in the circle;

· Full left: If it is "√", this test point ensures that all commands are directed to the left, that is, for any 1 <I <m, ai = 0;

· Si = 1: If it is "√", it indicates that the test point ensures that only one instruction is provided, that is, to any 1 ≤ I ≤ m, Si = 1;

· The occupation length is 1: If it is "√", it indicates that this test point ensures that the occupation of all toys and villains must be a string with a length of 1.


Pure simulation ....

If this year's noip still has such a question!

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 using namespace std; 6 const int MAXN = 100001; 7 int n, m, how, step; 8 struct node 9 {10 string name; 11 int to; 12} a [MAXN]; 13 int read (int & n) 14 {15 char ch = ''; int q = 0, w = 1; 16 for (; (ch! = '-') & (Ch <'0') | (ch> '9'); ch = getchar ()); 17 if (ch = '-') w =-1, ch = getchar (); 18 for (; ch> = '0' & ch <= '9 '; ch = getchar () q = q * 10 + ch-48; 19 n = q * w; return n; 20} 21 int main () 22 {23 // freopen ("toya. in "," r ", stdin); 24 // freopen (" toya. out "," w ", stdout); 25 read (n); read (m); 26 // scanf (" % d ", & n, & m ); 27 // ios: sync_with_stdio (false); 28 for (int I = 1; I <= n; ++ I) 29 {30 read (a [I]. to); 31 // scanf ("% d", & a [I]. to); 32 // cout <a [I]. to <"***************" <endl; 33 // 0 orientation inside the circle 1 orientation outside the circle 34 cin> a [I]. name; 35} 36 int where = 1; 37 for (int I = 1; I <= m; ++ I) 38 {39 read (how); read (step ); 40 // scanf ("% d", & how, & step); 41 // 0 left, 1 right 42 if (how = 0) 43 {44 if (a [where]. to = 0) // to 45 {46 where = where-step; 47 if (where <= 0) 48 where = where + n; 49} 50 else if (a [where]. to = 1) // to 51 {52 where = where + step; 53 if (where> n) 54 where = where-n; 55} 56} 57 else // number 58 to the right {59 if (a [where]. to = 0) 60 {61 where = where + step; 62 if (where> n) 63 where = where-n; 64} 65 else66 {67 where = where-step; 68 if (where <= 0) 69 where = where + n; 70} 71} 72} 73 cout <a [where]. name; 74 return 0; 75}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.