2011-04-13

30÷2(2+3)÷5=?

這是個語意解讀上的問題(1s)

啊講詳細點就是人和電腦對係數的處理方式不太統一。
而且人類在計算時,下意識進行的大量省去和結合等等都是電腦不懂得,電腦的優點只在於學會了之後很快而已(噴笑)


國小老師教我們
step1. 2+3 replace 5 括號優先
step2. 2(5) replace 10 係數優先
step3. 30÷10 replace 3 左結合
step4. 3÷5 replace 0.6 為最終解

如果電腦要達到這種解讀的話
必須在處理係數的時候,是用刮號以及乘號去取代:2(2+3) replace (2*(2+3))

另一個可能出現的解答15的原因在於係數只用乘法取代,原式變成30÷2*5÷5。

step1. 2 replace 2*
step2. (2+3) replace 5
step3. 30÷2 replace 15
step4. 15*5 replace 75
step5. 75÷5 replace 15

不過這很明顯不是使用者期望的....不過這邊,如朋友所言,這裡已經不是 syntax 的問題而是 semantics的問題啦XDDD


括號跟分數的簡化最好是每做完一步都check一下,這個check是自然演算法中的[下意識],但是電腦很笨(真正厲害的是工程師─請支持正版),所以你不寫一串不太直覺的處理沒辦法達到自然運算的效果。



至於/跟÷這兩個傢伙,在自然語言中的語意更是天差地遠。
A/B 解讀為分數,是用橫式表示直式的寫法。(...很令人頭暈齁...沒關係稱下去你就得到它了!!!)
A÷B 解讀為A除以B

雖然現在看起來一樣,但是丟到更長的式子裡去就很可怕了。

以下的ABCD為代數

手寫的 A/BC/D,是先解讀/號並自動加上刮號,是表示((A÷B)*(C÷D)),答案寫成AC/BD

但是(在某種不可能發生在人類自然解讀的情形下)
電腦對於A/BC/D解讀順序是先把B視為C的係數,(A/(B*C))/D,答案是A/BCD。

我compiler修得亂七八糟的,那些專有名詞都忘記系蝦毀惹。

2011-04-12

NP作業1

因為沒有閒置機器可供玩轉,所以先安裝虛擬機器
(以下說明網頁來自重灌狂人)


  • 一、在主電腦安裝VirtualBox軟體

  • 二、在VirtualBox建立新的虛擬電腦

  • 三、建立新的虛擬硬碟機

  • 四、選定開機光碟機

  • 五、啟動虛擬電腦、安裝作業系統

  • 六、安裝好系統,更新VirtualBox專屬驅動程式



  • 當然5.6那兩點跟作業需求的Unix-like不一樣。

    應用OS fedora,google後就有關網可供下載iso。

    虛擬光碟軟體:http://www.daemon-tools.cc/eng/home 我只裝了lite,其他功能用不到。


    接下來作業要求

    homework01 作業題目

    In this homework, you will write a simple Web server with C/C++ in the UNIX environment. The specification of this Web server is as follows:

    1. The Web server can be accessed from one of the GUI-based Web browsers, such as IE, Firefox, etc. (40%)

    (還好是一個就OK....)

    2. The user can access an HTML file on the server on the Web browser. (20%)

    3. The user can access a picture (in the format of JPEG or GIF, etc.) from the Web browser. (15%)

    4. The Web server can handle zombie processes well.(10%)

    5. Add 5 points for each new function (access control, support more data types, ...)

    Your Web server will listen on port 80 if possible (but not required). Please upload your report (in one or two pages) in PDF format to e-course by 4/6, and demonstrate your program to the TAs in that week.



    同學提供參考網址: http://www.jbox.dk/sanos/webserver.htm

    fedora沒有內建vim,這怎麼可以呢!!


    要先切到admin account才可以安裝。
    要改兩個檔案不要忘記了~



    如何在Fedora中安裝vim → http://hi.baidu.com/xuehuo_0411/blog/item/f34197968c49287d54fb9652.html

    yum install vim

    也不要忘記安裝gcc....



    [完成]
    以下是用office2010 power point快取圖樣做的流程圖



    2011-01-26

    Big-oh 和 master method

    這是今天補習時一直困擾我的兩樣東西

    所以乾脆就把東西查查寫寫,以造福後人。

    是說如果你不去看英文wiki反而來我這個部落格大概也是走投無路了,那我也就不害羞把有點白癡的想法寫下來了。

    補一個還滿詳細的Bog-Oh相關網頁 http://www.cyut.edu.tw/~ckhung/b/al/asympt.php
    排版有點不親民不過也只有這個毛病了

    2011-01-19

    關於矩陣那麼點兒事

    用 **array取代array[MAX][MAX]的好處不只有大小可以自己指定

    除了降低閱讀性稍微降低這個缺點外

    在各個thread中傳遞一個矩陣的指標比傳遞整個陣列本身來的容易

    缺點就是邊界限制不夠強…

    ex:

    在main中使用
    int **ary;
    ary = malloc((MAX+1)*sizeof(*ary));
    for(i=0;i<=MAX;i++)
    {ary[i]=malloc((MAX+1)*sizeof(**ary));    }


    你在thread的地方就可以直接



    void subForThread(int *ary)

    if(*(ary+j) > *(ary+j+1))
    {
    temp =*(ary+j);
    *(ary+j)=*(ary+j+1);
    *(ary+j+1)=temp;
    }



    2011-01-17

    OS

    ※ 引述《ch890333 (紅狼)》之銘言:
    > Typically, at the completion of a device I/O, a single interrupt is raised
    > and appropriately handled by the host processor. In certain settings,96
    > however, the code that is to be executed at the completion of the I/O
    > can be broken into two separate pieces, one of which executes imme-
    > diately after the I/O completes and schedules a second interrupt for
    > the remaining piece of code to be executed at a later time. What is the
    > purpose of using this strategy in the design of interrupt handlers?


    The purpose of this strategy is to ensure that the most critical
    aspect of the interrupt handling code is performed first and the less
    critical portions of the code is delayed for the future.

    這種兩截式策略是為了確保中斷重要的部份可以先被執行,不那麼重要的部份可以稍晚執行。

    For instance, when a device finishes an I/O operation, the device control
    operations corresponding to declaring the device as no longer being busy are
    more important in order to issue future operations.

    像是一個裝置完成IO後,會馬上發表相對聲明︰『我很閒!!!』以表明未來可以接受排程。

    However, the task of copying the data provided by the device to the
    appropriate user or kernel memory regions can be delayed for a future
    point when the CPU is idle.


    不過,像是把IO動作所copy的內容顯示給使用者或塞進kernel記憶體這些事情就可以讓CPU在未來有空的時候再做。

    In such a scenario, a latter lower priority interrupt handler is used to perform the copy operation.

    在這種情況下,(比基尼…我是說兩截式通知的)下半截/延遲/沒那麼重要的通知就會被運用在copy操作中。


    --
    快來人找我去翻譯課本!!

    2010-11-05

    出售女性二手衣物



    士林夜市購入

    平肩細格子

    加上腰封超顯瘦 因為要搭太麻煩故售出

    穿過一次 原價390 現售150

    2010-05-30

    跨瀏覽器真是件不容易的事情

    今天又收到一個不可思議的廣告信,不可思議的不是內容,而是他圖片切割的方法。


    仔細看的話你就會發現,這張圖切的非常細,而且更亮然感到驚奇的是,chrome到底是跟IE(還是fx?)有多大差別讓這張圖可以抽成這樣wwwwww

    原始碼什麼就沒有了,因為這些問題不可能是第一次出現,而且大家都知道,其實你用一整張圖就可以解決這種現象了。

    不過是廣告信,size不會大到哪裡去啊