UVa #10603 Fill (例题7-8) | 专攻挖掘机炒鸡蛋算法



UVa #10603 Fill (例题7-8) | 专攻挖掘机炒鸡蛋算法

UVa #10603 Fill (例题7-8)

看了书上的解法,自己写了一遍,几乎没遇到什么障碍。不过看Board上面的讨论,觉得细节上需要注意的地方还是挺多的。。纯粹自己写肯定分分钟跪下

1、vis数组只用开两维

看到讨论中大家都是用的三维数组vis[201][201][201],其实有了两杯水的数据,第三杯水可以用总量减去两杯水的量得到,所以不需要维护3维数组

2、解的存储

因为题目说如果取不到d,就要打印出比d小的最大的可能解d'以及倒水的量,所以bfs就把所有可能的d以及倒水量都存了下来,如果之前取到过这个d,则判断倒水量是否比之前的少,如果满足要求的话就更新数据。最后从d开始往下减小,遇到第一个取到过的解就打印并返回

3、优先队列

首先要注意这道题问的是倒水量最少,而不是倒水次数最少,而这两者没有必然关系。所以在bfs的时候,就不能用普通queue存储需要遍历的节点,而应该用一个优先队列,让倒水量少的排在前头。

另外在讨论中看到很多人用的是dfs,并且很多人得了TLE。然后大家比较推荐的解法是dijkstra。


Read full article from UVa #10603 Fill (例题7-8) | 专攻挖掘机炒鸡蛋算法


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts