UVa 101 (analog) The Blocks problem

Source: Internet
Author: User

Test instructions

There are n pieces of wood and n blocks of wood, and the initial state is the block I on the block I block on the first block. There are four operations, and then the final state is output.

Analysis:

Use a vector<int> to simulate a block heap and perform the appropriate operation.

1#include <iostream>2#include <cstdio>3#include <vector>4#include <string>5 using namespacestd;6 7 Const intMAXN = -;8 intN;9vector<int>PILE[MAXN];Ten  One voidFind_block (intAint& P,int&h) A { -      for(inti =0; I < n; ++i) -          for(intj =0; J < Pile[i].size (); ++j) the             if(Pile[i][j] = =a) -{p = i; h =J;} - } -  + voidClear_block (intPinth) -{//Place the block above the upper part of the p stack height to H +      for(inti = h +1; I < pile[p].size (); ++i) A     { at         intK =Pile[p][i]; - Pile[k].push_back (k); -     } -Pile[p].resize (H +1); - } -  in voidMove_onto (intPaintHintpb) -{//Stack wood blocks with a PA stack height of h and above onto a PB heap to      for(inti = h; I < pile[pa].size (); ++i) + Pile[pb].push_back (Pile[pa][i]); - pile[pa].resize (h); the } *  $ intMain ()Panax Notoginseng { -     //freopen ("In.txt", "R", stdin); the     intA, B; +scanf"%d", &n); A      for(inti =0; I < n; ++i) pile[i].push_back (i); the     strings1, S2; +      while(Cin >> S1 >> a >> s2 >>b) -     { $         intPA, Pb, ha, HB; $ Find_block (A, PA, ha); - Find_block (b, Pb, HB); -         if(PA = pb)Continue; the         if(S2 = ="onto") Clear_block (Pb, HB); -         if(S1 = ="Move") Clear_block (PA, ha);Wuyi Move_onto (PA, ha, pb); the     } -      for(inti =0; I < n; ++i) Wu     { -printf"%d:", i); About          for(intj =0; J < Pile[i].size (); ++J) printf ("%d", Pile[i][j]); $printf"\ n"); -     } -  -  A     return 0; +}
code June

UVa 101 (analog) The Blocks problem

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.