问题链接:。
问题简述:参见上述链接。
问题分析:这是一个模拟题,程序过程都是套路。
程序说明:程序中用到了STL的容器类vector。
开始的时候,编写的程序在UVA和POJ中都AC,可是在HDU中是“Presentation Error”。问题出在输出格式上,针对HDU另外写了一个程序就AC了,需要修改45行。这个格式问题很坑啊!!!
AC通过的C++语言程序如下:
/* UVA101 POJ1208 The Blocks Problem */#include#include #include using namespace std;const int MAXN = 25;vector pile[MAXN];// 找木块block的堆void find_block(int block, int& p, int& h, int n){ for(p=0; p > n; for(int i=0; i > command && command != "quit") { cin >> from >> action >> to; int frompile, fromheight, topile, toheight; find_block(from, frompile, fromheight, n); find_block(to, topile, toheight, n); if(frompile == topile) continue; if(command == "move") clear_above(frompile, fromheight); if(action == "onto") clear_above(topile, toheight); pile_onto(frompile, fromheight, topile); } output_result(n); return 0;}
AC通过的C++语言程序如下(HDU1612):
/* HDU1612 The Blocks Problem */#include#include #include using namespace std;const int MAXN = 25;vector pile[MAXN];// 找木块block的堆void find_block(int block, int& p, int& h, int n){ for(p=0; p > n; for(int i=0; i > command && command != "quit") { cin >> from >> action >> to; int frompile, fromheight, topile, toheight; find_block(from, frompile, fromheight, n); find_block(to, topile, toheight, n); if(frompile == topile) continue; if(command == "move") clear_above(frompile, fromheight); if(action == "onto") clear_above(topile, toheight); pile_onto(frompile, fromheight, topile); } output_result(n); return 0;}