2013年4月23日 星期二

Candy Crush Saga Level 356


今天 Candy Crush Saga 發表新單元,Level 351 ~ 365 啟動。



剩下十一步,一個條紋糖果在右下角四乘四,

附近又沒有辦法再造另個條紋糖果,這代表一件事,

我得在其他區域再造兩個條紋糖果,再想辦法黏在旁邊。



是該放棄了。




放棄前把糖果炸掉,死也要壯壯烈烈的死去,

刷著刷著,結果掉下來不偏不倚兩個條紋糖果又瞎貓摸耗子黏在旁邊




接著曼尼敲出延長賽兩分砲,不該放棄任何機會。

2013年4月22日 星期一

Depth-First Search


WIKI: http://en.wikipedia.org/wiki/Depth-first_search



實作細節:

1. 比起 Non-recursive implementation, recursive implementation 會佔用較多的 memory stack,無所謂好壞,只要能符合需求的就是好程式。

2. Graph 是有向圖或者是無向圖,這很重要。

例子:http://community.topcoder.com/stat?c=problem_statement&pm=1524&rd=4472 ((可能需要登入帳號))

product 1 competes with 2 => product 2 competes with 1,所以 graph 是無向圖。

using System;
using System.Collections.Generic;

namespace TopCoder.GraphPractice
{
    class Marketing
    {
        public long howMany(String[] compete)
        {
            Dictionary<int, Vertex> graph = GetGraph(compete);

            int arrangedCount = 0;

            foreach (Vertex vertex in graph.Values)
            {
                if (!vertex.Visited)
                {
                    vertex.Consumer = ConsumerGroup.Teenagers;
                    if (HasArrangement(vertex))
                    {
                        arrangedCount++;
                    }
                    else
                    {
                        return -1;
                    }
                }
            }

            return (long)Math.Pow(2, arrangedCount);
        }

        private Dictionary<int, Vertex> GetGraph(String[] compete)
        {
            Dictionary<int, Vertex> graph = new Dictionary<int, Vertex>();
            
            for (int i = 0; i < compete.Length; i++)
            {
                graph.Add(i, new Vertex());
            }

            for (int i = 0; i < compete.Length; i++)
            {
                String[] vertexList = compete[i].Split();
                foreach (String vertex in vertexList)
                {
                    if (!String.IsNullOrEmpty(vertex))
                    {
                        int j = Int32.Parse(vertex);
                        if (!graph[i].Neighborhood.ContainsKey(j))
                        {
                            graph[i].Neighborhood.Add(j, graph[j]);
                        }
                        if (!graph[j].Neighborhood.ContainsKey(i))
                        {
                            graph[j].Neighborhood.Add(i, graph[i]);
                        }
                    }
                }
            }

            return graph;
        }

        private bool HasArrangement(Vertex vertex)
        {
            bool hasArrangement = true;

            Stack<Vertex> stack = new Stack<Vertex>();
            stack.Push(vertex);

            while (stack.Count > 0)
            {
                Vertex top = stack.Pop();
                if (top.Visited)
                {
                    continue;
                }
                top.Visited = true;
                
                foreach (Vertex neighborhood in top.Neighborhood.Values)
                {
                    if (neighborhood.Consumer == ConsumerGroup.Unknown)
                    {
                        if (top.Consumer == ConsumerGroup.Teenagers)
                        {
                            neighborhood.Consumer = ConsumerGroup.Adults;
                        }
                        else if (top.Consumer == ConsumerGroup.Adults)
                        {
                            neighborhood.Consumer = ConsumerGroup.Teenagers;
                        }
                    }
                    else
                    {
                        if (top.Consumer == neighborhood.Consumer)
                        {
                            hasArrangement = false;
                        }
                    }

                    stack.Push(neighborhood);
                }
            }

            return hasArrangement;
        }

        private class Vertex
        {
            public Dictionary<int, Vertex> Neighborhood { get; set; }

            public bool Visited { get; set; }

            public ConsumerGroup Consumer { get; set; }

            public Vertex()
            {
                Neighborhood = new Dictionary<int, Vertex>();
                Visited = false;
                Consumer = ConsumerGroup.Unknown;
            }
        }

        private enum ConsumerGroup
        {
            Unknown,
            Adults,
            Teenagers
        }
    }
}

受傷的好處


今天是美女復健師幫我拉手,好開心,

這週一定很幸運頭上沒有羊角,早上台股莫名奇妙 (3,000) 那只是個蘊釀,

純種高粱的美味晚上才品嘗的到,

用力握美女的手,右手肌腱沒有炎,但是左手有炎。



為什麼自己摸不到?美女才摸的到!

長時間工作打電腦養成的繩子右手休息兩個月竟然好了,

醫院除了治病還能挖掘病,還是少讓美女復健師摸到,

不然奇奇怪怪的毛病又被摸出來,可怕。

2013年4月21日 星期日

[C#] Depth First Search


Problem Statement for grafixMask




using System;
using System.Collections.Generic;

namespace TopCoder.GraphPractice
{
    class grafixMask
    {
        public int[] sortedAreas(String[] rectangles)
        {
            bool[,] visited = GetBlockedPixels(rectangles);

            List<int> areas = new List<int>();

            for (int row = 0; row < 400; row++)
            {
                for (int col = 0; col < 600; col++)
                {
                    if (!visited[row, col])
                    {
                        areas.Add(GetConnectedArea(row, col, ref visited));
                    }
                }
            }

            areas.Sort();
            
            return areas.ToArray();
        }

        private bool[,] GetBlockedPixels(String[] rectangles)
        {
            bool[,] blocked = new bool[400, 600];

            foreach (String rectangle in rectangles)
            {
                String[] coordinates = rectangle.Split();
                int topLeftRow = Int32.Parse(coordinates[0]);
                int topLeftCol = Int32.Parse(coordinates[1]);
                int bottomRightRow = Int32.Parse(coordinates[2]);
                int bottomRightCol = Int32.Parse(coordinates[3]);

                for (int row = topLeftRow; row <= bottomRightRow; row++)
                {
                    for (int col = topLeftCol; col <= bottomRightCol; col++)
                    {
                        blocked[row, col] = true;
                    }
                }
            }

            return blocked;
        }

        // Depth first search.
        private int GetConnectedArea(int row, int col, ref bool[,] visited)
        {
            int area = 0;

            Stack<Vertex> stack = new Stack<Vertex>();
            stack.Push(new Vertex(row, col));

            while (stack.Count > 0)
            {
                Vertex top = stack.Pop();

                if (top.Row < 0 || top.Row >= 400) 
                {
                    continue;
                }
                if (top.Col < 0 || top.Col >= 600)
                {
                    continue;
                }

                if (visited[top.Row, top.Col])
                {
                    continue;
                }

                visited[top.Row, top.Col] = true;

                area++;

                stack.Push(new Vertex(top.Row + 1, top.Col));
                stack.Push(new Vertex(top.Row - 1, top.Col));
                stack.Push(new Vertex(top.Row, top.Col + 1));
                stack.Push(new Vertex(top.Row, top.Col - 1));
            }

            return area;
        }

        private class Vertex
        {
            public int Row { get; set; }

            public int Col { get; set; }

            public Vertex(int row, int col)
            {
                Row = row;
                Col = col;
            }
        }
    }
}

Gods often contradict our fondest expectations


Euripides, Medea

莫言,紅高粱家族



事情的發展總與想像相反,中間夾雜的人性,

非得自我毀滅不蒸饅頭爭口氣。

七星山苗圃登山口土地吸滿腫脹的雨水,那是起點,

尋找那兒噗噗拉屎神秘小徑,屎兒早已被雨水沖到山腳,

回到自來水廠,再給山下都市人們喝,

水有細菌不乾淨,拉屎回到土地,再用另一個方法回到石門水庫。

狗吃人肉,人再來吃狗肉。



現在台灣不吃狗肉,不文明,台灣尊重狗本,

不買狗認養狗,PIZZERIA OGGI 旁冰淇淋店拉布拉多小乖很饞嘴,

那家比薩店可好吃的,小乖不知有無吃過那軟細餅皮沾上張牙舞爪芝麻葉?



狗本注重以認養代替購買,也注重狗的體型,

減肥不是女生話題,而是狗本問題。

那些年我們錯過的運動,現在只能委屈的躲在健身房踩跑步機,

國北師操場比跑步機好上千萬倍,

有打排球的妹,有打籃球的妹,有跑步的妹,

真不曉得是流口水還是流汗水。



4000M、4000M、陽明山公車總站與苗圃登山口0.7K的來回。

2013年4月19日 星期五

Candy Crush Saga 每次看廣告的訊息


King.com da las gracias a sus anunciantes por ayudarnos a ofrecer unos juegos gratuitos geniales.

¡Recibirás tu recompensa cuando finalice el mensaje patrocinado!



Google翻譯:

King.com is grateful to our advertisers for helping to offering great free games.

You will receive your reward when you finish the message sponsored!

2013年4月18日 星期四

You've Broken Faith with Me


https://records.viu.ca/~johnstoi/euripides/medea.htm



如果就這麼繼續五年,

就這麼忍耐欣賞不想看的電影,任憑悲慘世界無聲無息,

就這麼沒有自己,

就這麼踏上多數人嚮往又噁爛的婚姻。



或許不提不會知道,帶上帽子羊角不會長出,

但他告訴我,在一起的時候你們就在一起,

我沒有潔癖,我沒有自我都無所謂,

但我想就這麼完成一件誰也沒辦法阻止我的事情,

這點要求並不過份,這點任性也很天真。



偶爾大方,不代表有義務請客,

與其說請客,不如說想做自己開心的事,

我又不是小丑,沒必要事事如人所願。



May I die a happy man.