Noip2016day1 Toy Puzzle Toy

Source: Internet
Author: User

Title Description

Small South has a cute toy villain, and they have different occupations.

One day, the dolls hid the little South's glasses. Small South found that the toys were surrounded by small people, some facing the inner circle, and some facing outside. Such as:

Then singer told Little South a puzzle: "The glasses hidden in my left number 3rd toy villain right number 1th toy villain's left number 2nd toy man there." ”

Small South found that the direction of the toy villain in this puzzle is very critical, because the inside and outside of the toy villain is opposite: the side of the toy villain, its left side is clockwise direction, the right is counterclockwise direction; While facing the outside of the toy villain, its left is counterclockwise direction, the right is clockwise direction.

Small south, while struggling to identify the toy villain, counted:

Singer Inward, the 3rd of the left is archer.

Archer outward, the 1th of the right is thinker.

Thinker outward, the 2nd of the left is writer.

So the glasses are hidden in writer's place!

Although the successful return of glasses, but small south and not relieved. If the next time more toys hide his glasses, or the length of the puzzle is longer, he may not be able to find his glasses. So small South wants you to write a program to help him solve a similar puzzle. Such puzzles can be described specifically as:

There are N toy men in a circle, known for their occupations and orientations. Now the 1th toy villain tells the small south a puzzle containing the m-directive, where the z-directive is shaped like "left/right number S, a toy villain". You need to output a number of these instructions in order to reach the toy villain's occupation.

Input/output format

Input format:

The first line of the input contains the west positive integer n,m, which represents the number of toys and the number of instructions.

Next n rows, each line contains an integer and a string that gives the direction and occupation of each toy villain in the order counter-clockwise. Where 0 is the direction of the circle, and 1 is toward the outside. Ensure that no other number is present. The string length does not exceed 10 and is composed only of lowercase letters, the string is not empty, and the string 22 is different. The question of integers and strings is separated by a space.

The next M-line, where the z-line contains two integer a,,s, represents the z-directive. If a,= 0, indicates left number s, individual, if a,= 1, means right number s, individual. Guarantee A, there will be no other number, 1≤s,<n.

output Format :

Outputs a string that represents the occupation of the villain from the first reading of the villain, followed by a number of M instructions.

Input/Output sample

Enter the sample #1:

9}

0 singer

0 Reader

0 Mengbier

1 thinker

1 Archer

0 writer

1 Mogician

0 3

1 1

0 2

The output sample #1:

Writer

Input Example # # :

10 10

1 C

2 0

1 1

1 d

1 E

1 m

1 T

1 y

1 u

1 7

1 7

1 1

1 4

0 5

0 3

0 1

1 6

1 2

0 8

0 4

Output Example # # :

Y

Description

"Sample 1 description"

This set of data is the example mentioned in "topic description".

"Subtasks"

Sub-tasks will give some of the characteristics of the test data. If you are having trouble solving the problem, you can try to solve only part of the test data.

The data size and characteristics of each test point are shown in the following table:

Some of these shorthand columns have the following meanings:

? Full-Face: If "√", indicating that the test point to ensure that all the toys are facing the inner circle;

Full left: If "√" means that the test point guarantees that all instructions are left-

1≤z≤m, ai=0;

s,= 1: If "√" means that the test point guarantees that all instructions are only 1, that is, for any

1≤z≤m, Si=1;

Career length is 1: if "√", indicating that the test point to ensure that all toy villain's occupation must be a

A string of length 1.

Ideas

examination, see such a problem, think of is simulation, easy to play, very mentally retarded step by step simulation, the result time-out.

There is no need to step-by-step simulation, just need to be in the original position Gaga minus minus can be done.

Topic points

a:0 1 North facing Circle outside

b:0 1 left to right

Can be summed up as

A0 B0 Clockwise

A0 B1 Counter-clockwise

A1 B0 Counter-clockwise

A1 B1 Clockwise

A+b if it is odd then counterclockwise, otherwise clockwise

#include <iostream>using namespacestd;intN,m;//Number of villain and instruction stripintCNT;intstart;BOOLk[100001]; stringppl[100001];voidUseintConintStep) {    intstep0=step%O; if((Con+k[start])%2==0)//Clockwise{Start-=step0; if(start<=0) start+=N; return; }    Else{Start+=step0; if(start>n) start-=N; return; }}intMain () {CIN>>n>>m;  for(intI=1; i<=n;i++) {cin>>k[i]>>Ppl[i]; }    BOOLcon; intstep; Start=1;  for(intI=1; i<=m;i++) {cin>>con>>step;    Use (Con,step); } cout<<Ppl[start];}

Noip2016day1 Toy Puzzle Toy

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.