NOIP2016 National Information Science Division League Improvement Group First Test toy puzzle

Source: Internet
Author: User

Toy Puzzle (Toy)

"Problem 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. The following figure:

At this time singer told small 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 critical, because the inside and outside of the toy villain is opposite: The toy villain facing the Circle, its left side is clockwise direction, the right side 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, the 3rd of the left is archer.
"Archer outward, the right number 1th is thinker."
"Thinker outward, the left number 2nd 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 dolls 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 M instruction, in which the article I instruction shape such as "left number/right number of Si toy villain". You need to output a number of these instructions in order to reach the toy villain's occupation.

"Input Format"

Reads data from the file toy.in.
The first line of input contains two positive integers n, m, indicating the number of toys and the number of instructions.
Next n rows, the Hungarian line contains an integer and a string that gives the direction and occupation of the Hungarian toy villain in order counterclockwise. 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 integer and string are separated by a space.
Next m line, where line I contains two integers ai, si, represents the i instruction. If Ai = 0, the left number Si personal, if ai = 1, the right number Si personal. Make sure AI does not appear in other numbers, 1≤si < n.

"Output Format"

Output to the file toy.out.
Outputs a string that represents the occupation of the villain from the first reading of the villain, followed by a number of M instructions.

Exercises

No words, violent simulations.

Code

type Arr=record st:string;
      Bo:boolean;
End
  var n,m:longint;
A:array [0..100001] of arr;
Procedure Init;
var i:longint;
  Begin READLN (N,M);
      For I:=1 to n do begin READLN (a[i].st);
      If a[i].st[1]= ' 0 ' then a[i].bo:=false else a[i].bo:=true;
    Delete (a[i].st,1,2);
End

End
Procedure main;
var i,x,y,t:longint;
  Begin T:=1;
      For I:=1 to M do begin READLN (x, y);
          If A[t].bo then BEGIN if x=0 then t:=t+y else t:=t-y;
          If T>n then t:=t-n;
        If T<1 then t:=t+n;
          End ELSE BEGIN if X=0 then t:=t-y else t:=t+y;
          If T>n then t:=t-n;
        If T<1 then t:=t+n;
    End
  End
Write (A[t].st);

End
  Begin init;
Main End. 

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.