pile专题

【SGU】271. Book Pile(双端队列模拟)

一摞书,2个操作,一个操作是在书堆上加一本,第二个将前K个书翻转 看别人用Splay树做的,但是可以用双端队列模拟,因为K个书之后的书位置已经定下来了,所以只需要记录在队列头加书还是尾加书 #include<cstdio>#include<string>#include<algorithm>#include<queue>#include<stack>#include<cstrin

URAL 1005 Stone Pile

这种题型: Balanced Partition    刚开始用的方法:    从最大的开始放,每次放到数量较小的那一堆上,最后看相差为多少。    这样很容易想,可惜是错的,反例如下。    5  10 9 8 7 2   如果这么算,分的是 (10,7) 和 (9,8,2)  相差2    而最小的答案是(10,8)和(9,7,2)  相差0     看了这

1005. Stone Pile 背包问题 动态规划

You have a number of stones with known weights w1, …, wn. Write a program that will rearrange the stones into two piles such that weight difference between the piles is minimal. Input