Ultraviolet A 101-the blocks Problem

Source: Internet
Author: User

It is not difficult to simulate the stack. You can handle the simultaneous situations of Block a and block B, but I still don't understand why the RE was so many times, if the array cn is small, it will be RE, but according to the topic, it is enough to open an array of cn [25] [25] at most, but I still want to open more than 100 or RE, as a result, the AC will be started over 200. I don't know why so far. Please explain it to me ~~~

# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; struct blocks {int M, N; char a [10]; char B [10];} ai [1000 + 5]; int CN [250 + 5] [250 + 5], CT [250 + 5]; // array? Int Sfind (INT num, int m) // find the corresponding building block {for (INT I = 0; I <num; I ++) for (Int J = 0; j <CT [I]; j ++) if (CN [I] [J] = m) return I; return 0;} int change (INT flagm, int m) // place the corresponding building blocks back to the original position {for (INT I = CT [flagm]-1; I> = 0; I --) if (CN [flagm] [I]! = M) {int GGT = cn [flagm] [I]; CN [GGT] [cT [GGT] ++] = cn [flagm] [I]; CT [flagm] --;} else break; return 0;} int Monto (int m, int N, int num) {int flagm, flagn; flagm = Sfind (Num, m); flagn = Sfind (Num, n); change (flagm, m); change (flagn, N ); CN [flagn] [cT [flagn] ++] = cn [flagm] [-- CT [flagm]; return 0;} int mover (int m, int N, int num) {int flagm, flagn; flagm = Sfind (Num, m); flagn = Sfind (Num, n); change (flagm, M ); CN [flagn] [cT [fla GN] ++] = cn [flagm] [-- CT [flagm]; return 0;} int Ponto (int m, int N, int num) {int flagm, flagn, flaga; flagn = Sfind (Num, n); flagm = Sfind (Num, m); change (flagn, n); For (INT I = 0; I <CT [flagm]; I ++) if (M = cn [flagm] [I]) {flaga = I; break;} For (INT I = flaga; I <CT [flagm]; I ++) Cn [flagn] [cT [flagn] ++] = cn [flagm] [I]; CT [flagm]-= CT [flagm]-flaga; return 0;} int pover (int m, int N, int num) {int flagm, flagn, flaga; flagn = Sfind (Num, n); flagm = Sfind (Num, m); For (INT I = 0; I <CT [flagm]; I ++) if (M = cn [flagm] [I]) {flaga = I; break;} For (INT I = flaga; I <CT [flagm]; I ++) CN [flagn] [cT [flagn] ++] = cn [flagm] [I]; CT [flagm]-= CT [flagm]-flaga; return 0 ;} int main () {# ifdef test freopen ("sample.txt", "r", stdin); # endif int num; while (scanf ("% d", & num )! = EOF) {int COUNT = 0; while (1) {getchar (); scanf ("% s", Ai [count]. a); If (strcmp (Ai [count]. a, "quit") = 0) break; scanf ("% d % S % d", & Ai [count]. m, Ai [count]. b, & Ai [count]. n); count ++;} For (INT I = 0; I <num; I ++) {CN [I] [0] = I; CT [I] = 1 ;}for (INT I = 0; I <count; I ++) {int flagm, flagn; flagn = Sfind (Num, Ai [I]. n); flagm = Sfind (Num, Ai [I]. m); If (flagm = flagn | ai [I]. N = ai [I]. m) continue; // four cases if (strcmp (Ai [I]. a, "move") = 0 & strcmp (Ai [I]. b, "onto") = 0) Monto (Ai [I]. m, Ai [I]. n, num); else if (strcmp (Ai [I]. a, "move") = 0 & strcmp (Ai [I]. b, "over") = 0) mover (Ai [I]. m, Ai [I]. n, num); else if (strcmp (Ai [I]. a, "pile") = 0 & strcmp (Ai [I]. b, "onto") = 0) Ponto (Ai [I]. m, Ai [I]. n, num); else if (strcmp (Ai [I]. a, "pile") = 0 & strcmp (Ai [I]. b, "over") = 0) pover (Ai [I]. m, Ai [I]. n, num) ;}for (INT I = 0; I <num; I ++) {printf ("% d:", I); For (Int J = 0; j <CT [I]; j ++) printf ("% d", CN [I] [J]); puts ("") ;}} return 0 ;}

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.