Zuma to eliminate (nausea)

Source: Internet
Author: User

"Problem description"


Zuma is a once-popular global game, the play is: in a track initially lined with a number of
Colored beads, where any three adjacent beads are not exactly the same color. After that, you can launch beads to
Track and add the original sequence. Once there are three or more beads of the same color become adjacent, they will stand
That disappears. Such elimination may occur in a chain, during which you will not be able to launch beads for the time being.
The developer is recently ready to write a playback tool for the player in the game process. They've done it inside the game.
The function of process recording, and the implementation of playback function is entrusted to you to complete.
The recording of the game process begins with the initial bead sequence on the track, followed by the player's next
A series of operations. Your task is to calculate the new bead sequence in time after each operation.


"Input Format"


The first line is a string consisting of an uppercase ' A ' ~ ' Z ' that represents the initial bead sequence on the track,
Different letters indicate different colors.
The second line is a number, which indicates that the entire playback process has a common operation.
The next line corresponds to each operation in turn. Each operation consists of a number and a capital letter?
Description, separated by a space. Which,? For the color of the new beads. If there are beads before insertion, then? ∈[0,?]
Indicates the order of the new beads in orbit after embedding (before elimination has occurred).


"Output Format"


Output a total line, given in turn each operation (and possibly immediately after the elimination phenomenon) on the track
sequence of beads.
If there are no beads on the track, the "-" is indicated.


"Sample Input"


Accba
5
2 A
0 A
2 B
4 C
0 A


"Sample Output"


Abccba
Aabccba
Aabbccba
-
A


"Sample Interpretation"


You think there's a grandfather clock temple in the mountains?


"Data size and conventions"


100% of the data meets 1≤? ≤10 3, 1≤? ≤2x10 3.

Ideas:

This is disgusting to die, the magic of the big simulation, Zhong said, the problem to be written in the list, but

I'm a slag konjac konjac.

Only the array is used to simulate, so a particularly straightforward simulation is written

Zuma this game is not how to play, so, there are a few rules to eliminate I do not know.

The code is also very difficult to write, but I still tenacious write it out;

This elimination of the situation there are many kinds, summed up the following several ways to eliminate:

1. When inserting an element, the same element is removed, plus the number of elements inserted is greater than 2;

2. In 1 of the case there are the same elements, and the number of the same element is greater than 2 will be eliminated;

3. When 1 is established, but 2 is not established, the number of elements that have been removed after the same element is more than 2 will be eliminated;

Come on, on the code;

#include <cstdio>#include<cstring>#include<iostream>using namespacestd;intn,cur;Charstr[6002],ch,vn;voidChangeintNow ) {    if(str[now]==0) str[now]=str[now-1]; Else{Change ( now+1); Str[now]=str[now-1]; }}voidQread (int&x) {x=0; vn=GetChar ();  while(vn<'0'|| Vn>'9') vn=GetChar ();  while(vn>='0'&&vn<='9') {x=x*Ten+(int) (vn-'0'); vn=GetChar ();}}voidCheckintNowCharty) {    intl=now-1, r=now,nl=0, nr=0, pd=0;  while(1)    {        if(str[l]==ty) nl++,l--; if(str[r]==ty) nr++,r++; if(Str[l]!=ty&&str[r]!=ty) Break; }    if(nl+nr+1>=3)    {         while(1) {NL=0, nr=0, ty=Str[l]; intLl=l,rr=R; intKol;  while(1) {Kol=0; if(str[l]==ty) L--, nl++,kol++; if(str[r]==ty) r++,nr++,kol++; if(kol==0) Break; }            if(nl==0|| nr==0|| nl+nr<3) {L=ll,r=RR;  Break; }        }         while(1)        {            intRr=r,kol=0; NR=0; if(str[r]!=0)            {                Charop=Str[r];  while(1)                {                    if(str[r]==op) {NR++; R++; }                    Else  Break; }            }            if(nr<3) {R=RR;  Break; }        }         while(1)//Because the second situation may occur after the 3rd case is eliminated, the method of handling the second case is used once;=0, nr=0, ty=Str[l]; intLl=l,rr=R; intKol;  while(1) {Kol=0; if(str[l]==ty) L--, nl++,kol++; if(str[r]==ty) r++,nr++,kol++; if(kol==0) Break; }            if(nl==0|| nr==0|| nl+nr<3) {L=ll,r=RR;  Break; }        }        intkol=r-l-1;  for(inti=l+1; i<r;i++) str[i]=0;  while(str[r]!=0) {Str[r-kol]=Str[r]; STR[R]=0; R++; }    }    Else    {Change ( now+1); Str[now]=Ty; }}voidprint () {if(str[0]==0) {Putchar ('-'); Putchar ('\ n'); return; }    intKcc=0;  while(str[kcc]!=0) {Putchar (STR[KCC]); KCC++; } Putchar ('\ n');}intMain () {get (str); the two-dimensional space-time CIN and scanf are difficult to read because the possible start sequence is empty, so this isif(str[0]=='\ n') str[0]=0;    Qread (n);  for(intI=1; i<=n;i++) {qread (cur); CIN>>ch;        Check (CUR,CH);    Print (); }    return 0;}

Zuma to eliminate (nausea)

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.