2009年3月25日 星期三

矩陣相乘

兩個二為矩陣的相乘,矩陣元素為浮點數,
Input 為 M1.txt M2.txt
Ouput 為 Output.txt
文字檔格式為
row
column
elements
例如2x3的矩陣:
2
3
1 2 3
4 5 6
=====結構與函式定義=====
// Matrix Structure
typedef struct MATRIX
{
 int row;
 int column;
 float **data;
}MAT;

// M3 = M1 * M2
MAT M1, M2, M3;

void Init(MAT &mat);
void Multiply(const MAT mat1, const MAT mat2, MAT &mat3);
void Clear();

=====Main.cpp=====
#include "matrix.h"
#include <stdio.h>

#define FtoI // Float to Integer

int main(int argc, char **argv)
{
 freopen("M1.txt","r",stdin);
 scanf("%d", &M1.row);
 scanf("%d", &M1.column);
 Init(M1);

 freopen("M2.txt","r",stdin);
 scanf("%d", &M2.row);
 scanf("%d", &M2.column);
 Init(M2);

 freopen("Output.txt","w",stdout);
 Multiply(M1, M2, M3);

 Clear();

 return 0;
}

// Allocate memory space to matrix structure
void Init(MAT &mat)
{
 mat.data = new float*[mat.row];

 for(int i=0; i<mat.row; i++)
  mat.data[i] = new float[mat.column];

 for(int i=0;i<mat.row;i++)
  for(int j=0;j<mat.column;j++)
  {
   float temp;
   scanf("%f", &temp);
   mat.data[i][j] = temp;
  }
}

// M3 = M1 * M2
void Multiply(const MAT mat1, const MAT mat2, MAT &mat3)
{
 if(mat1.column == mat2.row)
 {
  mat3.row = mat1.row;
  mat3.column = mat2.column;
  mat3.data = new float*[mat3.row];
  for(int i=0; i<mat3.row; i++)
   mat3.data[i] = new float[mat3.column];

  // Multiply
  for(int k=0; k<mat2.column; k++)
   for(int i=0; i<mat1.row; i++)
   {
    mat3.data[i][k] = 0;  // Set M3 to zero
    for(int j=0; j<mat2.row; j++)
     mat3.data[i][k] += mat1.data[i][j] * mat2.data[j][k];
   }

  printf("%d\n%d\n", mat3.row, mat3.column);
  for(int i=0;i<mat3.row;i++)
  {
   for(int j=0;j<mat3.column;j++)
#ifdef FtoI
    printf("%d\t", (int)mat3.data[i][j]);
#else
    printf("%f\t", mat3.data[i][j]);
#endif
   printf("\n");
  }
 }
 else
  printf("Dimentions error.\n");
}

// Release the memory space
void Clear()
{
 delete M1.data;
 delete M2.data;
 delete M3.data;
}

2009年3月15日 星期日

九年國教之上課塗鴉篇

http://www.wretch.cc/blog/b771018/13339407

只能說,台灣的未來 XD?

2009年3月1日 星期日

2009年2月24日 星期二

Lost In Translation

YouTube 配樂連結

實在是很平靜很耐聽又有味道的一首歌

加上女主角又很美

感覺 很棒

有機會來看看這部片好了 ( 愛情,不用翻譯 )

應該是不錯,是Scarlett Johansson早期所拍的電影

電影簡介

2009年2月23日 星期一

洋蔥頭腦殘檢定

看笨版意外看到的測驗 =ˇ=.... 檢測自己的腦殘程度!!

洋蔥頭腦殘檢定 ~~~ 不知道為什麼竟然是博客來的網頁 XDDDD

我的測驗結果:












Angie的測驗結果:












只能說 =ˇ= 其實還蠻準的嘛 XDDDDDDDDDDD

2009年2月11日 星期三

CodeBlocks、Dev-C++ 使用 OpenCV

CodeBlocks 設置方法Dev-C++ 設置方法

CodeBlocks:
1. Project → Build options...
2. Linker settings 中的 Other linker options: 加入
 -lhighgui -lcv -lcxcore
3. Serach directories 中的 Compiler 加入
 C:\Program Files\OpenCV\cxcore\include
 C:\Program Files\OpenCV\otherlibs\highgui
 C:\Program Files\OpenCV\cv\include
4.
Serach directories 中的 Linker 加入
 C:\Program Files\OpenCV\lib

Dev-C++:
1. 在 Tools → Compiler Options → Compiler → 將 Linker Command 的框框勾起來且加
 -lhighgui -lcv -lcxcore -lcvaux -lcvcam
2. Tools → Compiler Options → Directories → Libraries 加入
 C:\Program Files\OpenCV\lib
3. Tools → Compiler Options → Directories → C Includes 加入
 C:\Program Files\OpenCV\cxcore\include
 C:\Program Files\OpenCV\cv\include
 C:\Program Files\OpenCV\otherlibs\highgui
 C:\Program Files\OpenCV\cvaux\include
 C:\Program Files\OpenCV\otherlibs\cvcam\include
4. Tools → Compiler Options → Compiler → Directories → C++ Includes
 C:\Program Files\OpenCV\cxcore\include
 C:\Program Files\OpenCV\cv\include
 C:\Program Files\OpenCV\otherlibs\highgui
 C:\Program Files\OpenCV\cvaux\include
 C:\Program Files\OpenCV\otherlibs\cvcam\include

使用 CodeBlocks 每次開新專案都要重新再加入路徑

而 Dev-C++ 則不用

但是用 Dev-C++ 又不好 tracing code = =.... 真是討厭

Asshole Mario



這個版本真的是超難的啦 = =~~~

竟然還有神人可以破關 Orz...

其他還有各關的影片在 YouTube 搜尋 Asshole Mario 即可找到~

2009年1月14日 星期三

She's like the Swallow - Williams College Elizabethans



以前在合唱團有唱過這首,同樣是STAB混聲四部,

好懷念,希望可以復團,好想唱歌。

2009年1月11日 星期日

Yesterday Once More - 木匠兄妹



When I was young I'd listen to the radio.當我還是小女還時,我常聽收音機。
Waiting for my favorite songs.等待著我心愛的歌。
When they played I'd sing along.當它們播放出來的時候,我會跟著唱。
It make me smile.這令我笑容滿面。

Those were such happy times and not so long ago.不久前的回憶那真是段美好的時光。
How I wondered where they'd gone.我不知道那段美好時光怎麼消失了。
But they're back again just like a long lost friend.現在它們就像久無音信的老朋友又回來了。
All the songs I love so well.所有的歌都是我所喜歡的。
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!

Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!

When they get to the part.當他們唱到那段-
Where he's breaking her heart.男孩使女孩傷心的部分時。
It can really make me cry.也讓我流下了眼淚。
Just like before.就像昔日一樣。
It's yesterday once more ! 仿佛昨日重現!
(Shoobie do lang lang)
(Shoobie do lang lang)
Looking back on how it was in years gone by. 回首過去的幾年。
And the good times that had.以及我曾擁有的好時光。
Makes today seem rather sad.使今日更加傷感。
So much has changed ! 太多的轉變!

It was songs of love that I would sing to them.那些舊日跟唱過的舊情歌。
And I'd memorise each word.我仍然記得沒一句歌詞。
Those old melodies still sound so good to me.那些舊旋律聽起來仍然那麼悅耳。
As they melt the years away.它們使歲月消融!
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!

Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!
All my best memorise come back clearly to me.所有美好的回憶都在我腦海裡清晰的浮現!
Some can even make me cry.有些甚至令我淚流滿脈面。

Just like before.就象昔日一樣。
It's yesterday once more ! 仿佛昨日重現!
(Shoobie do lang lang)
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!
Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!
Every shalala every wo'wo still shines ! 每一個紗啦啦,每一個哦哦依舊閃耀!
Every shing-a-ling-a-ling that they're starting to sing.他們開始唱的每一個昕鈴鈴-
So fine ! 都如此美妙!

Love Is All Around - Wet Wet Wet



Love Is All Around

I feel it in my fingers, I feel it in my toes
Love is all around me and so the feeling grows
It's written on the wind, it's everywhere I go
So if you really love me, come on and let it show
You know I love you I always will
My mind's made up by the way that I feel
There's no beginning, there'll be no end
'Cause on my love you can depend
I see your face before me, as I lay on my bed
I kinda get to thinking of all the things we said
You gave a promise to me, and I gave mine to you
I need someone beside me in everything I do
You know I love you I always will
My mind's made up by the way that I feel
There's no beginning, there'll be no end
'Cause on my love you can depend
It's written on the wind, it's everywhere I go
So if you really love me, come on and let it show
Come on and let it show

2009年1月6日 星期二

Matrix

CvArr → CvMat → IplImage ( 繼承關係 )
Even though OpenCV is implemented in C, the structures used in OpenCV have an object-oriented design; in effect, IplImage is derived from CvMat, which is derived from CvArr

1.
When CvArr* appears, it is acceptable to pass CvMat* or IplImage* to the routine.

可以用 CvArr * 去接 CvMat 或是 IplImage

上層往下指,上層的每一個成員下層也一定都有,所以一定都會對滿

反之,下層有的上層不見得有,所以下層的指標有些會接不到東西,就錯誤

故可以用上層的指標去接下層的成員函式。

2.
CvArr, can be thought of as an abstract base class from which CvMat is itself derived.

抽象基礎類別

是把最底層的class成員函數都宣告成virtual,本身的class沒辦法實體化

只提供該有哪些function的功能

實體的使用內容卻是由衍生出來的class去各自設計

也就是提供類似模組或樣版

第二點的參考資料來源:奇摩知識+

萍聚