摘要: 题目:1934. 移动小球思路: 想了很久,即使用链表在插入和删除元素的时候比较快,但用来查找删除插入的位置的时间也太长。 看了别人的代码之后顿时开窍,用两个数组分别记录每一个球的左边和右边球的编号,这样就可以实现数组对元素的快速访问。非常高明而简单的方法!感觉有点类似于基于数组实现的双端链表。代码: 1 #include 2 using namespace std; 3 4 int lefts[500001]; //lefts[i] stores the lefts ball's number of the ball i. 5 int rights[500001]; //rights 阅读全文
posted @ 2013-11-10 20:49 Jolin123 阅读(585) 评论(5) 推荐(0) 编辑
摘要: 题目:DescriptionFarmer John has decided to take a family portrait of some (maybeall) of the cows. In order to take the portrait, FJ has arrangedall N (1 1 1 0 1 0 1 1+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+... 阅读全文
posted @ 2013-11-10 12:12 Jolin123 阅读(498) 评论(0) 推荐(0) 编辑