2012年9月15日 星期六

Prime(Basic Method)

C++ code colored by C++2HTML
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    bool b;
    int i,j,end, ans[100] = {2};
    end = 1;
    for(i=3;;i+=2)
    {
        b = false;
        for(j=0;j<end;j++)
        {
            if(0 == i%ans[j])
            {
                b = true;
                break;
            }
        }
        if(false == b)
        {
            ans[end] = i;
            ++end;
        }
        if(100 == end)break;
    }
    for(j=0;j<end;j++)cout<<ans[j]<<endl;//print 100 prime numbers
    system("PAUSE");
    return 0;
}

2012年5月11日 星期五

遊戲構想:One Touch板 飛機特訓

前幾天看到同事拿手機在玩One Touch板的 俄羅斯方塊,
也就是掉下來的地方,用One Touch的方式,選擇掉落的位址。
使我想到一個遊戲構想,也就是One Touch板的 飛機特訓,
想法是,飛機特訓 改成 用One Touch的方式選擇電腦選出的逃生路徑,
但是 很快的想到, 逃生路徑要怎麼由電腦算出來?且夠快算出來?
我一時想不出來,所以將此構想發表在Blog上。

2012年1月28日 星期六

基金投資小心得

一、買單筆,不買定時定額。
定時定額,賺的沒比較多,賠的也沒比較少,不如買單筆。
二、買積極型基金,不買穩健型基金。
所謂穩健型基金,不一定是真的,只是賺的比較少,賠的沒少多少。
而PIMCO總回報算是真的穩健型基金,但是別人在賺超過10%時,
PIMCO總回報賺不超過3%…還是買積極型基金比較好賺。
三、不要想避險,亂買基金。
譬如想避險的話,一筆買拉丁美洲,一筆買東歐,如此通常會有一筆或二筆一起跌。
四、逢低買進,逢高賣出。
逢低加碼通常能賺錢,不要被壞消息,嚇的不敢加碼了。

2011年12月29日 星期四

My SPOJ status

pfiesteria's user data

Current world rank: #5136

(2 points)

Country: TAIWAN, PROVINCE OF CHINA

Modify user data
My job application

Problems solved Solutions submitted Solutions accepted Wrong Answer Compile Error Runtime Error Time Limit Exceeded
21 178 53 43 7 16 59

History of submissions
(plaintext version)

List of solved classical problems:
ADDREV GNY07A PRIME1
CANDY JULKA RESN04
CANTON NHAY SAMER08F
DIVSUM NSTEPS SBANK
FASHION ONP SQRBR
FCTRL PALIN TEST
FCTRL2 PIR TOANDFRO

TODO list of classical problems:

2011年2月6日 星期日

UVa : 11705 (Grasshopper) « Solved Programming Problems

UVa : 11705 (Grasshopper) « Solved Programming Problems:
//用link的Code來釐清題意,之後寫出以下AC Code.




C++ code colored by C++2HTML





#include <cstdlib>
#include <iostream>


using namespace std;

int g_input[50][50], g_dis[50][50];

char ga[50][50];

int jump(char direct, int y, int x, int row, int col)
{

    if('N' == direct)
    {
        if(y - g_input[y][x] >= 0)
        {

            return g_dis[y - g_input[y][x]][x];
        }

        else return 0;
    }
    else if('W' == direct)
    {
        if(x - g_input[y][x] >= 0)
        {

            return g_dis[y][x - g_input[y][x]];
        }

        else return 0;
    }
    else if('E' == direct)
    {
        if(x + g_input[y][x] < col)
        {

            return g_dis[y][x + g_input[y][x]];
        }

        else return 0;    
    }
    else if('S' == direct)
    {
        if(y + g_input[y][x] < row)
        {

            return g_dis[y + g_input[y][x]][x];
        }

        else return 0;
    }
    
}

int proc(int i, int j, int row, int col, char d[][50])
{

    int min=200,temp;
    
    temp = jump('N',i,j,row,col);

    if(temp > 0)
    {
        min = temp;

        d[i][j] = 'N';
    }
    
    temp = jump('W',i,j,row,col);

    if(temp > 0)
    {
        if(temp < min)
        {

            min = temp;
            d[i][j] = 'W';
        }
    }

    
    temp = jump('E',i,j,row,col);

    if(temp > 0)
    {
        if(temp < min)
        {

            min = temp;
            d[i][j] = 'E';
        }
    }

    
    temp = jump('S',i,j,row,col);

    if(temp > 0)
    {
        if(temp < min)
        {

            min = temp;
            d[i][j] = 'S';
        }
    }

    
    if(min != 200)return min;
    else return 0;
    
}

int proc_last(int i, int j, int row, int col, char d[][50])
{

    int min=200,temp;   
    
    temp = jump('S',i,j,row,col);

    if(temp > 0)
    {
        if(i + g_input[i][j] < row)
        {

            if(temp < g_dis[i][j] - 1)
            {
                min = temp;

                d[i][j] = 'S';
                g_dis[i][j] = temp + 1;
            }

            else if(temp == g_dis[i][j] - 1 && d[i][j] == 'X')
            {

                min = temp;
                d[i][j] = 'S';

                g_dis[i][j] = temp + 1; 
            }
        }
    }

    temp = jump('E',i,j,row,col);

    if(temp > 0)
    {
        if(j + g_input[i][j] < col)
        {

            if(g_dis[i][j + g_input[i][j]] < g_dis[i][j] - 1)
            {

                min = temp;
                d[i][j] = 'E';

                g_dis[i][j] = temp + 1;
            }
            else if(temp == g_dis[i][j]-1 && (d[i][j] == 'X' || d[i][j] == 'S'))
            {

                min = temp;
                d[i][j] = 'E';

                g_dis[i][j] = temp + 1;    
            }
        }
    }
    
    temp = jump('W',i,j,row,col);

    if(temp > 0)
    {
        if(j - g_input[i][j] >= 0)
        {

            if(g_dis[i][j - g_input[i][j]] < g_dis[i][j] - 1)
            {

                min = temp;
                d[i][j] = 'W';

                g_dis[i][j] = temp + 1;
            }
            else if(temp == g_dis[i][j]-1 && (d[i][j] == 'X' || d[i][j] == 'S' || d[i][j] == 'E'))
            {

                min = temp;
                d[i][j] = 'W';

                g_dis[i][j] = temp + 1;    
            }
        }
    }
    
    temp = jump('N',i,j,row,col);

    if(temp > 0)
    {
        if(i - g_input[i][j] >= 0)
        {

            if(g_dis[i - g_input[i][j]][j] < g_dis[i][j] - 1)
            {

                min = temp;
                d[i][j] = 'N';

                g_dis[i][j] = temp + 1;
            }
            else if(temp == g_dis[i][j] - 1 && d[i][j] != 'N')
            {

                min = temp;
                d[i][j] = 'N';

                g_dis[i][j] = temp + 1;
            }
        }
    }
 
    if(min != 200)return min;

    else return 0;
    
}

void pt(int row, int col)
{

    int i,j;
    
        for(i=0;i<row;i++)
        {

            for(j=0;j<col;j++)
            {
                cout<<ga[i][j];
            }

            cout<<endl;
        }
}

void debug_d(int row, int col)
{

    int i,j;
    for(i=0;i<row;i++)
    {

        for(j=0;j<col;j++)
        {
            cout<<g_dis[i][j]<<" ";
        }

        cout<<endl;
    }
}

int main()
{
    bool end = false;

    int row, col, i, j, temp;    
    while(1)
    {

        cin>>row>>col;
        if(0 == row || 0 == col)break;

        for(i=0; i<row; i++)
        {
            for(j=0; j<col; j++)
            {

                cin>>g_input[i][j];
            }
        }
        memset(g_dis, 0, sizeof(g_dis));

        memset(ga, 'X', sizeof(ga));
        end = false;

        ga[0][0] = '*';
        for(j=1; j<col; j++)
        {

            if(g_input[0][j] == j)
            {
                ga[0][j] = 'W';

                g_dis[0][j] = 1;
            }
        }
        for(i=1; i<row; i++)
        {

            if(g_input[i][0] == i)
            {
                ga[i][0] = 'N';

                g_dis[i][0] = 1;
            }
        }
        while(end != true)
        {

            end = true;
            for(i=0; i<row; i++)
            {

                for(j=0; j<col; j++)
                {
                    if(0 == i && 0 == j)continue;

                    if(g_dis[i][j] > 0)continue;
                    else

                    {
                        temp = proc(i,j,row,col,ga);

                        if(temp > 0)
                        {
                            g_dis[i][j] = temp+1;

                            end = false;
                        }
                    }
                }//end for j
            }//end for i
        }//while
        //last proc
        end = false;

        while(end != true)
        {
            //debug_d(row, col);
            //system("PAUSE");
            end = true;

            for(i=0; i<row; i++)
            {
                for(j=0; j<col; j++)
                {

                    if(0 == i && 0 == j)continue;

                    else
                    {
                        temp = proc_last(i,j,row,col,ga);

                        if(temp > 0)
                        {
                            //temp
                            //cout<<"ga["<<i<<"]["<<j<<"]="<<ga[i][j]<<endl;
                            //end temp*/

                            end = false;
                        }
                    }
                }//for j
            }//for i
        }//while
        //end last proc
        pt(row, col);

        cout<<endl;
    }//while(1)
    return 0;
}






2010年9月7日 星期二

十月唱空

安徽省 民歌

Title: 十月唱空

正月唱來正月空,
吃了年糕拜祖宗。
有錢老爹去賭錢,
無錢老爹去幫工。

二月唱來二月空,
老爹帶信去上工,
大喜圓一數二十個,
帶把老婆小相公。

三月唱來三月空
手拿馬鞭向南沖,
抬頭望我姐姐在挑水,
眼睛哭得賽桃紅。

四月唱來四月空,
挑担黃秧下南沖,
毛草尖兒刺了腳,
延挨延挨要下工。

五月唱來五月空,
手拿鋤頭下南沖,
快鋤頭一用沙沙響,
鈍鋤頭不怕用死小長工。

六月唱來六月空,
背了水車下南沖,
低地就往高地倒,
不怕車死小長工。

七月唱來七月空,
手拿鐮刀下南沖,
快刀一割沙沙響,
鈍刀割死小長工。

八月唱來八月空,
手拿鐵鍬下南沖,
快鍬一剷沙沙響,
鈍鍬剷死小長工。

九月唱來九月空,
麥稻成堆滿倉中,
老爹吃的是白米,
不怕勞死你小長工。

十月唱來十月空,
拿條板凳坐橋東,
長工走來攔頭坐,
喊聲老爹算賬工。

你老有吃又有喝,
我長工肚裏唱空城,
還望你老行慈悲,
償我工錢好過冬。

你老若不把工錢償,
我長工一家難活命,
千謝萬謝謝你老,
積善人家有餘慶。

窮光蛋

安徽省 民歌

Title: 窮光蛋

出了東門往東看,
鎳臘白頂一大片。
要說是軍功,
未與長毛戰。
要說是科甲,
未演弓和箭。
再過二年整,
日子主還是日子主,
窮光蛋還是窮光蛋。

Lean 4 極簡教學 (Using VS Code on macOS)

 1. Install Lean Environment: https://lean-lang.org/install/ 試著完Step one, two, three 2. 在VS code下,建一新的project: 取名Hello_World 3. 嘗試執行Main.lea...