pile

木块问题/The Blocks Problem(Uva 101)

扶醉桌前 提交于 2019-11-27 08:17:50
原题摘录 输入n,得到编号为0~n-1的木块,分别摆放在顺序排列编号为0~n-1的位置。现对这些木块进行操作,操作分为四种。 1、move a onto b:把木块a、b上的木块放回各自的原位,再把a放到b上; 2、move a over b:把a上的木块放回各自的原位,再把a发到含b的堆上; 3、pile a onto b:把b上的木块放回各自的原位,再把a连同a上的木块移到b上; 4、pile a over b:把a连同a上木块移到含b的堆上。 当输入quit时,结束操作并输出0~n-1的位置上的木块情况 输入输出见文末. 题目分析 每个木块堆的高度不确定,所以用vector来保存很合适;而每个木块堆的个数不超过n,所以用一个数组来存就可以了. vector<int> pile[maxn];//一个存储int向量的数组 分析原题中的四个操作: 归位 移顶 move a归位 均有- onto b归位 且均为- 即move又onto a,b均归位 将a往b- pile/over 无 放 发现这是个指令有很多共同点,根据这样编写的函数就会减少重复代码.也即一个归位函数和一个移顶函数以及查出位置的辅助函数.所以有时不用指令完全独立. 完整代码(详细注释) #include <cstdio> #include <cstring> #include <cmath> #include

An old Stone Game

寵の児 提交于 2019-11-26 22:54:47
An old Stone Game Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 3691 Accepted: 1042 http://poj.org/problem?id=1738 Description There is an old stone game.At the beginning of the game the player picks n(1<=n<=50000) piles of stones in a line. The goal is to merge the stones in one pile observing the following rules: At each step of the game,the player can merge two adjoining piles to a new pile.The score is the number of stones in the new pile. You are to write a program to determine the minimum of the total score. Input The input contains several test cases. The first line of each

POJ 2234 Matches Game

烂漫一生 提交于 2019-11-26 20:59:07
Description Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from the pile (Of course the number of matches, which is taken away, cannot be zero and cannot be larger than the number of matches in the chosen pile). If after a player’s turn, there is no match left, the player is the winner. Suppose that the two players are all very clear. Your job is to tell whether the player who plays first can win the game or not. Input The input consists of