2008年12月29日 星期一

大力推薦兩款 Steam 的遊戲

傳送門展示影片



惡靈勢力恐怖開頭動畫中文化

靈異照片恐怖排行前9名



不知道為什麼...聽到大師的解說...我笑了 Orz...

2008年12月27日 星期六

371 - Ackermann Functions ( Time limit exceeded )

Time limit: 3.000 seconds

Ackermann Functions

An Ackermann function has the characteristic that the length of the sequence of numbers generated by the function cannot be computed directly from the input value. One particular integer Ackermann function is the following:

displaymath32

This Ackermann has the characteristic that it eventually converges on 1. A few examples follow in which the starting value is shown in square brackets followed by the sequence of values that are generated, followed by the length of the sequence in curly braces:

     [10] 5 16 8 4 2 1 {6}
[13] 40 20 10 5 16 8 4 2 1 {9}
[14] 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 {17}
[19] 58 29 88 44 22 ... 2 1 {20}
[32] 16 8 4 2 1 {5}
[1] 4 2 1 {3}

Input and Output

Your program is to read in a series of pairs of values that represent the first and last numbers in a closed sequence. For each closed sequence pair determine which value generates the longest series of values before it converges to 1. The largest value in the sequence will not be larger than can be accomodated in a 32-bit Pascal LongInt or C long. The last pair of values will be 0, 0. The output from your program should be as follows:

Between L and H, V generates the longest sequence of S values.

Where:

L = the lower boundary value in the sequence

H = the upper boundary value in the sequence

V = the first value that generates the longest sequence, (if two or more values generate the longest sequence then only show the lower value) S = the length of the generated sequence.

In the event that two numbers in the interval should both produce equally long sequences, report the first.

Sample Input

  1 20
35 55
0 0

Sample Output

Between 1 and 20, 18 generates the longest sequence of 20 values.
Between 35 and 55, 54 generates the longest sequence of 112 values.

=======================================================

#include <stdio.h>
#include <stdlib.h>

/* function prototype */

void Ackermann(const int,const int);
int find_length(const int);

int main()
{
 freopen("Input.txt","r",stdin);
 freopen("Output.txt","w",stdout);
 int L,H;
 while(scanf("%d%d",&L,&H)==2)
  if(L|H)
   Ackermann(L,H);
 return 0;
}

/* scan from lower bound to upper bound */
void Ackermann(const int L,const int H)
{
 int i,max_len=L,max_num=find_length(L);
 for(i=L+1;i<=H;i++)
 {
  int temp=find_length(i);
  if(max_num<temp)
  {
   max_len=i;
   max_num=temp;
  }
 }
 printf("Between %d and %d, %d generates the longest sequence of %d values.\n",L,H,max_len,max_num);
}

/* return the sequence number of value "V" */
int find_length(const int V)
{
 int count=0,x=V;
 do
 {
  count++;
  x=(!x%2)?(x/2):(3*x+1);
 }while(x!=1);
 return count;
}

靈犬尋寶

問題敘述:

正方形(左下角座標為(0,0),右上角座標為(99,99))的格網上,有一隻靈犬要尋找一個寶物,格網上除了靈犬與寶物之外,還有一些障礙物。一般情況下,只要不超出格網的邊界,靈犬的每一步最多有8 個方向可供選擇,如圖一;



但是必須注意,只有在A 點沒有障礙物時才可以選擇方向1 或方向2,只有在B點沒有障礙物時才可以選擇方向3 或方向4,只有在C 點沒有障礙物時才可以選擇方向5 或方向6,只有在D 點沒有障礙物時才可以選擇方向7 或方向8。如果靈犬可以從出發的位置走到寶物的位置,其總共使用的步數,理論上應有一個最小值;但是靈犬也有可能無法走到寶物的位置。過程中,靈犬不可以
走到障礙物的位置上。



以圖二為例,有多達4 個障礙物介於靈犬與寶物之間,但是靈犬最快只要2步就可以到達寶物的位置。圖三是另一個例子,靈犬的位置靠近角落,雖然只有2 個障礙物,靈犬卻無法到達寶物的位置。請撰寫一個程式,若靈犬可以從最初位置走到寶物的位置時,請列印出其使用之最少步數;若靈犬無法到達寶物的位置,請列印出單字『impossible』。

輸入說明:

第一行為一個整數n,代表障礙物的個數,0 ≦ n ≦ 1000。接下來的n 行,每行表示一個障礙物的座標,其橫座標值與縱座標值間以一個空白隔開。再下來的一行,表示靈犬的最初位置,其橫座標值與縱座標值間以一個空白隔開。最後一行,代表寶物的位置,其橫座標值與縱座標值間以一個空白隔開。注意:輸入之障礙物、靈犬、寶物皆在不同位置。所有橫、縱座標值均為介於0(含)至99(含)之間的整數。

輸出說明:

依行走之規則,若靈犬可以從其位置走到寶物的位置時,請列印出其使用之最少步數;若靈犬無法到達寶物的位置,請列印出單字『impossible』。

輸入範例1:
4
3 6
4 5
5 4
6 3
3 3
7 5

輸出範例1:
2

輸入範例2:
2
1 1
0 2
0 1
4 3

輸出範例2:
impossible

====================================================
Note. 所求為最少步數,故不必記錄路徑,使用BFS一步步逼近寶物,也
   不會有走到重複點卻需要覆蓋的問題,且由於水平或垂直的移動皆
   為偶數的組合步,故每一步的上下左右都無法走到,頂多只會有棋
   盤的一半被走到。
====================================================

#include <stdio.h>
#include
<stdlib.h>

#define BOARD_SIZE 100
#define MAX_QUEUE BOARD_SIZE*BOARD_SIZE/2


/* global variables */

int board[BOARD_SIZE+6][BOARD_SIZE+6];
/* the direction index of the dog's moving directions */
int dir_ver[8]={1,-1,-3,-3,-1,1,3,3};
int dir_hor[8]={3,3,1,-1,-3,-3,-1,1};
/* the direction index of the obstacles */
int dir_block_ver[4]={0,-1,0,1};
int dir_block_hor[4]={1,0,-1,0};

/* data structure of the queue */
typedef struct Position
{
 /* location */
 int x;
 int y;
 /* number of foot steps */
 int count;
}Position;

Position pos[MAX_QUEUE];

/* function prototype */

void initial(const int,const int,const int,const int [],const int []);
int find(const int,const int,const int,const int);

int main()
{
 /* read and open the input file named "H04dat.txt" */
 FILE *fp;
 fp=fopen("H04dat.txt","r");
 int i,ans,obstacle;

 /* set up the blocks */
 fscanf(fp,"%d",&obstacle);
 int x[obstacle],y[obstacle];
 for(i=0;i<obstacle;i++)
  fscanf(fp,"%d%d",&x[i],&y[i]);

 /* set up the start and end points */
 int start_x,start_y,end_x,end_y;
 fscanf(fp,"%d%d",&start_x,&start_y);
 fscanf(fp,"%d%d",&end_x,&end_y);

 /* intialize the board */
 initial(start_x+3,start_y+3,obstacle,x,y);

 /* if the treasure and the dog is on the same location */
 if(start_x==end_x&&start_y==end_y)
  printf("0\n");
 else
  /* find the treasure */
  if((ans=find(start_x+3,start_y+3,end_x+3,end_y+3))>0)
   printf("%d\n",ans);
  else
   /* if the treasure and the obstacle is on the same location */
   printf("impossible\n");

 /* close the input file */
 fclose(fp);

 system("PAUSE");
 return 0;
}

/* initialize the board */
void initial(const int sx,const int sy,const int obstacle,const int x[],const int y[])
{
 int i,j;
 /* set the outside boundary to -1, others to 0 */
 for(i=0;i<BOARD_SIZE+6;i++)
  for(j=0;j<BOARD_SIZE+6;j++)
   board[i][j]=(i>2&&i<BOARD_SIZE+3&&j>2&&j<BOARD_SIZE+3)?0:-1;

 /* put down the blocks */
 for(i=0;i<obstacle;i++)
  board[y[i]+3][x[i]+3]=-1;

 /* because it's meaningless that move to the start point */
 board[sy][sx]=-1;

 /* initialize the queue */
 pos[0].x=sx;
 pos[0].y=sy;
 pos[0].count=0;
}

/* return the minimum steps if the dog can find the treasure, */
/* return 0 if false */
int find(const int sx,const int sy,const int ex,const int ey)
{
 int i,j,idx;

 /* the four directions of each foot step are unreachable */
 if((ex+sx+ey+sy)%2)
  return 0;

 /* scan the whole queue */
 for(i=0,idx=1;i<idx;i++)
 {
  /* if the dog has already found the treasure then return the steps */
  /* use this condition may run more times "if(pos[i].y==ey&&pos[i].x==ex)" */
  if(board[ey][ex]!=0)
   return board[ey][ex];

  /* using BFS the find out the next eight directions */
  for(j=0;j<8;j++)
   /* if the obstacle is not near the dos's present location */
   if(board[pos[i].y+dir_block_ver[j/2]][pos[i].x+dir_block_hor[j/2]]!=-1)
    /* if any direction is reachable then PUSH into the queue */
    if(!board[pos[i].y+dir_ver[j]][pos[i].x+dir_hor[j]])
    {
     pos[idx].x=pos[i].x+dir_hor[j];
     pos[idx].y=pos[i].y+dir_ver[j];
     pos[idx++].count=pos[i].count+1;
     board[pos[i].y+dir_ver[j]][pos[i].x+dir_hor[j]]=pos[i].count+1;
    }
 }
}

2008年12月26日 星期五

369 - Combinations

Time limit: 3.000 seconds

Combinations

Computing the exact number of ways that N things can be taken M at a time can be a great challenge when N and/or M become very large. Challenges are the stuff of contests. Therefore, you are to make just such a computation given the following:

GIVEN:

displaymath41

Compute the EXACT value of:

displaymath43

You may assume that the final value of C will fit in a 32-bit Pascal LongInt or a C long.

For the record, the exact value of 100! is:

     93,326,215,443,944,152,681,699,238,856,266,700,490,715,968,264,381,621,
468,592,963,895,217,599,993,229,915,608,941,463,976,156,518,286,253,
697,920,827,223,758,251,185,210,916,864,000,000,000,000,000,000,000,000

Input and Output

The input to this program will be one or more lines each containing zero or more leading spaces, a value for N, one or more spaces, and a value for M. The last line of the input file will contain a dummy N, M pair with both values equal to zero. Your program should terminate when this line is read.

The output from this program should be in the form:

N things taken M at a time is C exactly.

Sample Input

     100  6
20 5
18 6
0 0

Sample Output

100 things taken 6 at a time is 1192052400 exactly.
20 things taken 5 at a time is 15504 exactly.
18 things taken 6 at a time is 18564 exactly.
===========================================

#include <stdio.h>
#include <stdlib.h>

int gcd(int,int);
void combi(const int,const int);

int main()
{
 freopen("Input.txt","r",stdin);
 freopen("Output.txt","w",stdout);
 int N,M;
 while(scanf("%d%d",&N,&M)==2)
  if(N|M)
   combi(N,M);
 return 0;
}

/* calculate the combinition number */
void combi(const int N,const int M)
{
 int A[M],B[M];
 int i,j;
 for(i=0;i<M;i++)
 {
  A[i]=N-i;
  B[i]=i+1;
 }
 for(j=1;j<M;j++)
  for(i=0;i<M;i++)
  {
   /* find the GCD of each pair when B[] is not 1 */
   int GCD=gcd(A[i],B[j]);
   if(GCD>1)
   {
    A[i]/=GCD;
    B[j]/=GCD;
   }
   if(B[j]==1)
    break;
  }
 /* when all elements in B[] are 1 then multiply every element in A[] */
 long ans=1;
 for(i=0;i<M;i++)
  ans*=A[i];
 printf("%d things taken %d at a time is %d exactly.\n",N,M,ans);
}

/* return (x,y) by recursive */
int gcd(int x,int y)
{
 return (!y)?x:gcd(y,x%y);
}

2008年12月24日 星期三

松青

晚上去松青買了大罐的飲料回家存放 =ˇ=

結果不小心一個手滑沒抓好,掉落一瓶小瓶的巧克力到地上,

劈啪!瓶子破了 >"< 今天整個很奇怪,一直掉東西

不好意思的去跟clerk說,還讓她去拖地,最後像是經理的人出現,

跟我說就不用賠了沒關係,不知道他是因為上面貼著五折還是怎樣才會這樣說,

總之,服務態度還算不錯 ( 好像錯在我 XD? )

結論:clerk 長的很可愛 >///<

2008年12月22日 星期一

350 - Pseudo-Random Numbers

Time limit: 3.000 seconds


Pseudo-Random Numbers

Computers normally cannot generate really random numbers, but frequently are used to generate sequences of pseudo-random numbers. These are generated by some algorithm, but appear for all practical purposes to be really random. Random numbers are used in many applications, including simulation.

A common pseudo-random number generation technique is called the linear congruential method. If the last pseudo-random number generated was L, then the next number is generated by evaluating ( tex2html_wrap_inline32 , where Z is a constant multiplier, I is a constant increment, and M is a constant modulus. For example, suppose Z is 7, I is 5, and M is 12. If the first random number (usually called the seed) is 4, then we can determine the next few pseudo-random numbers are follows:

tabular21

As you can see, the sequence of pseudo-random numbers generated by this technique repeats after six numbers. It should be clear that the longest sequence that can be generated using this technique is limited by the modulus, M.

In this problem you will be given sets of values for Z, I, M, and the seed, L. Each of these will have no more than four digits. For each such set of values you are to determine the length of the cycle of pseudo-random numbers that will be generated. But be careful: the cycle might not begin with the seed!

Input

Each input line will contain four integer values, in order, for Z, I, M, and L. The last line will contain four zeroes, and marks the end of the input data. L will be less than M.

Output

For each input line, display the case number (they are sequentially numbered, starting with 1) and the length of the sequence of pseudo-random numbers before the sequence is repeated.

Sample Input

7 5 12 4
5173 3849 3279 1511
9111 5309 6000 1234
1079 2136 9999 1237
0 0 0 0

Sample Output

Case 1: 6
Case 2: 546
Case 3: 500
Case 4: 220
============================================

#include <stdio.h>
#include <stdlib.h>

/* function prototype */
int random_length(const int,const int,const int,int);

int main()
{
 freopen("Input.txt","r",stdin);
 freopen("Output.txt","w",stdout);
 int Z,I,M,L,data_num=0;
 while(scanf("%d%d%d%d",&Z,&I,&M,&L)==4)
  if(Z|I|M|L)
   printf("Case %d: %d\n",++data_num,random_length(Z,I,M,L));
 return 0;
}

/* return the length of the random number cycle */
int random_length(const int Z,const int I,const int M,int L)
{
 /* record the random numbers */
 /* module 4-digit number only get 0~9998 */
 int array[9999];
 int i,j,count,ap;
 for(ap=0,count=1;;count++)
 {
  array[ap++]=L;
  L=(Z*L+I)%M;
  for(j=0;j<ap;j++)
   if(L==array[j])
    /* find the begin of the cycle */
    return count-j;
 }
}

344 - Roman Digititis

Time limit: 3.000 seconds

Roman Digititis

Many persons are familiar with the Roman numerals for relatively small numbers. The symbols ``i", ``v", ``x", ``l", and ``c" represent the decimal values 1, 5, 10, 50, and 100 respectively. To represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right. For example, the number 3 is represented as ``iii", and the value 73 is represented as ``lxxiii". The exceptions to this rule occur for numbers having units values of 4 or 9, and for tens values of 40 or 90. For these cases, the Roman numeral representations are ``iv" (4), ``ix" (9), ``xl" (40), and ``xc" (90). So the Roman numeral representations for 24, 39, 44, 49, and 94 are ``xxiv", ``xxxix", ``xliv", ``xlix", and ``xciv", respectively.

The preface of many books has pages numbered with Roman numerals, starting with ``i" for the first page of the preface, and continuing in sequence. Assume books with pages having 100 or fewer pages of preface. How many ``i", ``v", ``x", ``l", and ``c" characters are required to number the pages in the preface? For example, in a five page preface we歓l use the Roman numerals ``i", ``ii", ``iii", ``iv", and ``v", meaning we need 7 ``i" characters and 2 ``v" characters.

Input

The input will consist of a sequence of integers in the range 1 to 100, terminated by a zero. For each such integer, except the final zero, determine the number of different types of characters needed to number the prefix pages with Roman numerals.

Output

For each integer in the input, write one line containing the input integer and the number of characters of each type required. The examples shown below illustrate an acceptable format.

Sample Input

1
2
20
99
0

Sample Output

1: 1 i, 0 v, 0 x, 0 l, 0 c
2: 3 i, 0 v, 0 x, 0 l, 0 c
20: 28 i, 10 v, 14 x, 0 l, 0 c
99: 140 i, 50 v, 150 x, 50 l, 10 c
================================================

#include <stdio.h>
#include <stdlib.h>

/* function prototype */
void digit_change(int,int [5]);

int main()
{
 freopen("Input.txt","r",stdin);
 freopen("Output.txt","w",stdout);
 int num,i,count[5];
 while(scanf("%d",&num)==1)
  if(num!=0)
  {
   /* reset the number counting array */
   for(i=0;i<5;i++)
    count[i]=0;
   for(i=1;i<=num;i++)
    digit_change(i,count);
   printf("%d: %d i, %d v, %d x",num,count[0],count[1],count[2]);
   printf(", %d l, %d c\n",count[3],count[4]);
  }
 return 0;
}

/* return every elements of Roman digit from 1 to num */
void digit_change(int num,int count[5])
{
 /* handle the exception "100" */
 if(num==100)
 {
  count[4]++;
  return;
 }
 /* the representations of units and tens are the same, */
 /* just differenct at count[] index shift */
 int i,n,k,times=1;
 if(num>9)
  times=2;
 for(i=0,k=0,n=num%10;i<times;i++,k+=2,n=num/10)
  if(n!=0)
   /* separate one digit to three phases */
   if(n>0&&n<4)
    count[0+k]+=n;
   else if(n>3&&n<9)
   {
    count[1+k]++;
    count[0+k]+=abs(n-5);
   }
   else
   {
    count[0+k]++;
    count[2+k]++;
   }
}

2008年12月21日 星期日

352 - The Seasonal War

Time limit: 3.000 seconds

The Seasonal War

The inhabitants of Tigerville and Elephantville are engaged in a seasonal war. Last month, Elephantville successfully launched and orbited a spy telescope called the Bumble Scope. The purpose of the Bumble Scope was to count the number of War Eagles in Tigerville. The Bumble Scope, however, developed two problems because of poor quality control during its construction. Its primary lens was contaminated with bugs which block part of each image, and its focusing mechanism malfunctioned so that images vary in size and sharpness.

The computer programmers, who must rectify the Bumble Scope's problems are being held hostage in a Programming Contest Hotel in Alaland by elephants dressed like tigers. The Bumble Scope's flawed images are stored by pixel in a file called Bumble.in. Each image is square and each pixel or cell contains either a 0 or a 1. The unique Bumble Scope Camera (BSC) records at each pixel location a 1 if part or all of a war eagle is present and a 0 if any other object, including a bug, is visible. The programmers must assume the following:

a)
A war eagle is represented by at least a single binary one.

b)
Cells with adjacent sides on common vertices, which contain binary ones, comprise one war eagle. A very large image of one war eagle might contain all ones.

c)
Distinct war eagles do not touch one another. This assumption is probably flawed, but the programmers are desperate.

d)
There is no wrap-around. Pixels on the bottom are not adjacent to the top and the left is not adjacent to the right (unless, of course, there are only 2 rows or 2 columns)

Input and Output

Write a program that reads images of pixels from the input file (a text file), correctly counts the number of war eagles in the images and prints the image number and war eagle count for that image on a single line in the output file (also a text file).

Use the format in the sample output. Do this for each image in the input file. Each image will be preceded by a number indicating its square dimension. No dimension will exceed 25.

Sample input

6
100100
001010
000000
110000
111000
010100
8
01100101
01000001
00011000
00000010
11000011
10100010
10000001
01100000

Sample output

Image number 1 contains 3 war eagles.
Image number 2 contains 6 war eagles.

=========================================================

#include <stdio.h>
#include <stdlib.h>

#define MAX_DIM 25

/* functions prototype */
int find_eagle(int);
void DFS(int,int,int,int);

/* global variables */
int map[MAX_DIM+2][MAX_DIM+2];
int map2[MAX_DIM+2][MAX_DIM+2];

int main()
{
freopen("Input.txt","r",stdin);
freopen("Output.txt","w",stdout);
int dimention,data_num=0;
while(scanf("%d",&dimention)==1)
{
char row[dimention];
int i,j;
for(i=1;i<=dimention;i++)
{
scanf("%s",row);
for(j=1;j<=dimention;j++)
map[i][j]=row[j-1]-'0';
}
printf("Image number %d contains %d war eagles.\n",++data_num,find_eagle(dimention+2));
}
return 0;
}

/* return how many eagles */
int find_eagle(int dim)
{
int i,j,label=1;
/* map2 is the object label image map */
for(i=0;i<MAX_DIM+2;i++)
for(j=0;j<MAX_DIM+2;j++)
map2[i][j]=0;
/* if there's a point is 1 then find it's connected points */
for(i=1;i<dim-1;i++)
for(j=1;j<dim-1;j++)
if(map[i][j]==1&&map2[i][j]==0)
DFS(i,j,label++,dim);
return label-1;
}

/* mark the connected points with same label with eight directions */
void DFS(int x,int y,int lab,int dim)
{
/* if this point (x,y) hasn't been marked */
if(map2[x][y]==0)
{
map2[x][y]=lab;
if(map[x+1][y+1]==1)
DFS(x+1,y+1,lab,dim);
if(map[x+1][y]==1)
DFS(x+1,y,lab,dim);
if(map[x+1][y-1]==1)
DFS(x+1,y-1,lab,dim);
if(map[x][y-1]==1)
DFS(x,y-1,lab,dim);
if(map[x-1][y-1]==1)
DFS(x-1,y-1,lab,dim);
if(map[x-1][y]==1)
DFS(x-1,y,lab,dim);
if(map[x-1][y+1]==1)
DFS(x-1,y+1,lab,dim);
if(map[x][y+1]==1)
DFS(x,y+1,lab,dim);
}
}

A Question Of Honor - Sarah Brightman



Ebbene? ... N'andro lontana,
Come va l'eco della pia campana,
La, fra la neve bianca;
La, fra le nubi d'or;
La, dov'e la speranza, la speranza
Il rimpianto, il rimpianto, e il dolor!
Two men collide
When two men collide, when two men collide
It's a question of honour
Two men collide
When two men collide, when two men collide
It's a question of honour
Two men collide
When two men collide, when two men collide
If you win or you lose,
It's a question of honour
And the way that you choose,
It's a question of honour
I can't tell what's wrong or right
If black is white or day is night
But I know when two men collide
It's a question of honour
If you win or you lose,
It's a question of honour
And the way that you choose,
It's a question of honour
If you win or you lose,
It's a question of honour
And the way that you choose,
It's a question of honour
I can't tell what's wrong or right
If black is white or day is night
I know when two men collide
It's a question of honour
Ebbene? ... N'andro lontana,
Come l'eco della pia campana,
La, fra la neve bianca;
La, fra le nubi d'or;
N'andro, n'andro sola e lontana!
E fra le nubi d'or!

2008年12月20日 星期六

343 - What Base Is This? (Wrong Answer)

Time limit: 3.000 seconds

What Base Is This?

In positional notation we know the position of a digit indicates the weight of that digit toward the value of a number. For example, in the base 10 number 362 we know that 2 has the weight tex2html_wrap_inline28 , 6 has the weight tex2html_wrap_inline30 , and 3 has the weight tex2html_wrap_inline32 , yielding the value tex2html_wrap_inline34 , or just 300 + 60 + 2. The same mechanism is used for numbers expressed in other bases. While most people assume the numbers they encounter everyday are expressed using base 10, we know that other bases are possible. In particular, the number 362 in base 9 or base 14 represents a totally different value than 362 in base 10.

For this problem your program will presented with a sequence of pairs of integers. Let�'s call the members of a pair X and Y. What your program is to do is determine the smallest base for X and the smallest base for Y (likely different from that for X) so that X and Y represent the same value.

Consider, for example, the integers 12 and 5. Certainly these are not equal if base 10 is used for each. But suppose 12 was a base 3 number and 5 was a base 6 number? 12 base 3 = tex2html_wrap_inline52 , or 5 base 10, and certainly 5 in any base is equal to 5 base 10. So 12 and 5 can be equal, if you select the right bases for each of them!

Input

On each line of the input data there will be a pair of integers, X and Y, separated by one or more blanks; leading and trailing blanks may also appear on each line, are are to be ignored. The bases associated with X and Y will be between 1 and 36 (inclusive), and as noted above, need not be the same for X and Y. In representing these numbers the digits 0 through 9 have their usual decimal interpretations. The uppercase alphabetic characters A through Z represent digits with values 10 through 35, respectively.

Output

For each pair of integers in the input display a message similar to those shown in the examples shown below. Of course if the two integers cannot be equal regardless of the assumed base for each, then print an appropriate message; a suitable illustration is given in the examples.

Sample Input

12   5
10 A
12 34
123 456
1 2
10 2

Sample Output

12 (base 3) = 5 (base 6)
10 (base 10) = A (base 11)
12 (base 17) = 34 (base 5)
123 is not equal to 456 in any base 2..36
1 is not equal to 2 in any base 2..36
10 (base 2) = 2 (base 3)

=====================================================================

#include <stdio.h>
#include <stdlib.h>
#include <
math.h>

int length(char *,int);
int base_test(char *,int,int);
int find(char *,char *);

/* flag of least bases */
int max[2];

int main()
{
 freopen("Input.txt","r",stdin);
 freopen("Output.txt","w",stdout);
 char s1[100],s2[100];
 while(scanf("%s%s",s1,s2)==2)
  if(find(s1,s2)==0)
   printf("%s is not equal to %s in any base 2..36\n",s1,s2);
 return 0;
}

/* return string length and set the minimum base */
int length(char *str,int key)
{
 int i,base=str[0];
 for(i=1;str[i]!='\0';i++)
  if(base
<str[i])
  base=str[i];
 base=(base-'0'>9)?(base-'A'+10+1):(base-'0'+1);
 max[key]=base;
 return i;
}

/* count the sumation in base "base" to decimal number */
int base_test(char *str,int len,int base)
{
 int i,sum=0,weight;
 for(i=0;i<len;i++)
 {
  weight=(str[len-i-1]-'0'>9)?(str[len-i-1]-'A'+10):(str[len-i-1]-'0');
  sum+=weight*(int)pow(base,i);
 }

 return sum;
}

/* return 0 if they are not equal at any base, 1 otherwise */
int find(char *s1,char *s2)
{
 int i,j;
 int len1=length(s1,0);
 int len2=length(s2,1);
 for(i=max[0];i
<=36;i++)
  for(j=max[1];j
<=36;j++)
   if((base_test(s1,len1,i))==(base_test(s2,len2,j)))
   {
    printf("%s (base %d) = %s (base %d)\n",s1,i,s2,j);
    return 1;
   }
 return 0;
}

2008年12月19日 星期五

Display a Picture

專案->屬性->組態屬性->連結器->輸入->其他相依性

需填入 cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib 這些會用到的否則無法正常編譯!

#include "highgui.h"

int main(int argc, char** argv)
{
 IplImage* img=cvLoadImage(argv[1]);
 cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE);
 cvShowImage("Example1",img);
 cvWaitKey(0);
 cvReleaseImage(&img);
 cvDestroyWindow("Example1");
 return 0;
}

/* IplImage 為函式庫中的圖檔結構 */
/* cvLoadImage() 可讀取大部分的圖片檔案,有路徑的地方如C:\需用C:\\代替 */
/* cvLoadImage()回傳一個pointer */
/* 可輸入第二個參數 */
/* -1:預設讀取圖像的原通道數,0:強制轉化讀取圖像為灰階,1:讀取彩色影像 */
IplImage* img=cvLoadImage("file path",int);

/* console之外再創一個視窗且命名為"title" */
/* 第二個參數會將圖片縮放為符合開啟的視窗大小,預設是1 */
cvNamedWindow("title",CV_WINDOW_AUTOSIZE);

/* 在名為"title"的window中顯示讀取到的結構資料 */
cvShowImage("title",IplImage *);

/* 若參數為0或負數,則等鍵盤輸入一個按鍵才結束 */
/* 若參數為正數N,則會暫停N毫秒 */
cvWaitKey(int);

/* 釋放所配給的記憶體,指令完成後會將poniter指向NULL */
cvReleaseImage(&img);

/* 關閉視窗且會釋放跟此有關且有使用的記憶體,包含image buffer */
/* 雖然程式結束後都會自動的釋放記憶體,但卻不是個好習慣 */
cvDestroyWindow("Example1");

2008年12月18日 星期四

暮光之城


三件事我很確定:
第一、愛德華是吸血鬼
第二、出於天性,他渴望喝我的血
第三、我無可救藥地愛上他了……

  貝拉從繁華的鳳凰城搬到偏僻且陰雨不斷的福克斯,她原本認為往後的日子會很無聊,但當她遇上神祕又迷人的愛德華之後,生活開始變得刺激有趣,心也深深地被吸引。到目前為止,愛德華一家人身為吸血鬼的秘密,在福克斯是不為人知的,而如今,所有人都陷入險境,特別是貝拉──愛德華最摯愛的人。
  他們之間濃烈的愛意,讓兩人就像在刀尖上行走,在慾望與危險間掙扎著求取平衡。


Preface
  我將如何死亡,我並沒怎麼多想──雖然最後這幾個月,我的確有足夠的理由來思考這個問題──但就算我真的想過,也想像不到會是這般的情景。
  我屏住呼吸、走過長廊,凝望獵人漆黑的雙眼,他愉悅的看著我。
  這的確是個挺好的死亡方法:在一個只有我愛的人與我同在的地方。可以算是壯麗的,應該是值得的……
  我知道,如果我沒來福克斯,現在的我就無須面對死亡,但是,無論我有多害怕,我對這個決定永不後悔。當生命給你一個超乎預期的夢想時,就算即將死亡,也不應悲傷。
  獵人給我一個友善的微笑,從容的向前──殺死我。

2008年12月17日 星期三

暮光之城:無懼的愛 ( twilight )


































預告片中文版

劇情簡介:

如果可以永遠不死,那你要為誰而活?

貝拉史旺(克莉絲汀史都華飾演)一直有點特立獨行,在她唸的鳳凰中學裡,從來就不在乎和愛時髦的女同學處不處得來。母親改嫁之後,把貝拉送去華盛頓州佛斯 小鎮,和她的父親同住,可是她萬萬沒想到會發生重大的改變,直到她遇見了神秘又俊美的艾德華卡倫(羅伯派亭森飾演),她沒見過像他這樣的男孩。他聰明又機 智,一眼就看穿了她的靈魂。過不了多久,貝拉和艾德華就展開了一場激烈又違反傳統的愛情。艾德華跑起來比美洲獅還要快,可以赤手空拳攔下一輛行駛中的汽 車,而且他從1918年就到現在,一點也沒有變老。他和所有的吸血鬼一樣,都是永生不死的,可是他沒有尖牙,也不吸人血,因為艾德華和他的家人有別於其他 的吸血鬼,他們選擇了不同的生活方式。

對艾德華而言,貝拉是他等待了90年才得到的靈魂伴侶,不過他們愈是親近,艾德華就愈要拼命抵抗對 她身上氣味的本能吸引力,否則他有可能會抓狂到難以控制的地步。後來,與卡倫家族對立的羅倫(艾迪蓋瑟吉飾演)和詹姆斯(凱姆吉甘特飾演)來到這個小鎮尋 找貝拉,他該怎麼辦才好呢?


關於小說
史蒂芬妮梅爾的暢銷小說《暮光之城》,在國內熱賣550萬本,連續32週登上《紐約 時報》暢銷書排行榜,這是同系列小說的第一部。《暮光之城》是一個文化現象,有基本的忠實書迷,迫不及待想看改編拍成的電影。《暮光之城》有一百多個書迷 網站,也被幾大出版商選為年度風雲小說,已經被翻譯成20種語言了。這是一部現代版的羅密歐與茱麗葉,敘述吸血鬼和人類之間禁忌的愛。

=======================================================

雖然背景像是決戰異世界般有吸血鬼及萊肯,卻不是動作片,而是偏向愛情方面,

不像一般的吸血鬼電影主打驚悚、血腥、特效,想帶給人的是另外一種感受,

如同劇情簡介第一句話,如此簡單的問題,卻又難以回答,某幾幕中其實有被感動到,

不論是親情或是愛情成分,極端的情緒更能讓觀眾有所感受,男主角演的不錯,

不過可能礙於片長問題,感覺很難感受到一些細節,好想買小說來看!

我覺得是部不錯又值得看的電影,續集應該會更吸引人。

Practice of Using an Array of Pointers to Functions

Write a menu-driven interface to process student grades by using an array of pointers to
functions. The student grades are collected as follows:

Student ID Test#1 Test#2 Test#3 Test#4
  1     77   68   86   73
  2     96   87   89   78
  3     70   90   86   81

The program should offer the user four options as follows:

Enter a choice:
0 Print all grades for all students
1 Find the minimum grade of the total 12 grades
2 Find the maximum grade of the total 12 grades
3 Print the average on all tests for each student
4 End program

An individual function should be written for each of the choices from choice 0 through
choice 3, respectively. Store the pointers to the four functions in an array and use the
choice made by the user as the subscript into the array for calling each function. (Note
that: one restriction on using arrays of pointers to functions is that all the pointers must
have the same type. The pointers must be to functions of the same return type that receive
arguments of the same type.)

#include <stdio.h>
#include
<stslib.h>

void print_all(int [][4]);
void find_min(int [][4]);
void find_max(int [][4]);
void print_ave(int [][4]);

int main()
{
 int grade[3][4]={{77,68,86,73},{96,87,89,78},{70,90,86,81}};
 void (*array[4])(int [][4])={print_all,find_min,find_max,print_ave};

 for(;;)
 {
  int request;
  printf("0 Print all grades for all students\n");
  printf("1 Find the minimum grade of the total 12 grades\n");
  printf("2 Find the maximum grade of the total 12 grades\n");
  printf("3 Print the average on all tests for each student\n");
  printf("4 End program\n");
  scanf("%d",&request);
  if(request==4)
   break;
  else if(request>=0&&request<=3)    (*array[request])(grade); // &grade is the same
  else printf("Invalid input.\n");
 }
 system("PAUSE");
 return 0;
}

void print_all(int grade[][4])
{
 printf("\nStudent ID Test#1 Test#2 Test#3 Test#4\n");
 int i,j;
 for(i=0;i<3;i++)
 {
  printf("%4d%13d%7d",i+1,grade[i][0],grade[i][1]);
  printf("%7d%7d\n",
,grade[i][2],grade[i][3]);
 }
 printf("\n");
}

void find_min(int grade[][4])
{
 int i,j,min=101;
 for(i=0;i<3;i++)
  for(j=0;j
<4;j++)
   if(min>grade[i][j])
    min=grade[i][j];
 printf("\nThe minimum of all grades is : %d\n\n",min);
}

void find_max(int grade[][4])
{
 int i,j,max=-1;
 for(i=0;i
<3;i++)
  for(j=0;j
<4;j++)
   if(max
<grade[i][j])
    max=grade[i][j];
printf("\nThe maximum of all grades is : %d\n\n",max);
}

void print_ave(int grade[][4])
{
 printf("\n");
 int i;
 for(i=0;i<3;i++)  {   printf("The average of student ID %d is : ",
,i+1);
  printf("%lf\n",(grade[i][0]+grade[i][1]+grade[i][2]+grade[i][3])/4.0);
 }
 printf("\n");

}

Pointers to Functions

§Pointer to function
Contains address of function
Similar to how array name is address of first element
Function name is starting address of code that defines function

§Function pointers can be
Passed to functions
Stored in arrays
Assigned to other function pointers

§Example: bubblesort
Function bubble takes a function pointer
-bubble calls this helper function
-this determines ascending or descending sorting
The argument in bubblesort for the function pointer:
int ( *compare )( int a, int b ) tells bubblesort to expect a pointer to a function that takes
two ints and returns an int
If the parentheses were left out: int *compare( int a, int b )
-Defines a function that receives two integers and returns a pointer to a int
Function Pointers:


Pointers to Functions:


2008年12月16日 星期二

六芒星棋遊戲:先還是後比較有利?

問題敘述:
在一個稱為『六芒星』的星球上,流行著一種『六芒星棋』的遊戲。這種遊戲是由兩個人來比賽,道具是一個棋盤(如圖一)和13 個鐵圈。遊戲的起始狀態是由兩人互相協調或隨機決定,使用m 個(1 ≦ m ≦ 13)鐵圈在棋盤上圈住m個數字。接下來雙方輪流移除棋盤上的鐵圈,每人每次只能移除1個鐵圈或2個相鄰的鐵圈(有直線直接相連的位置視為相鄰),被迫移除最後一個鐵圈的人算輸。

其實如果仔細思考,可以證明不管起始狀態如何,遊戲中先移除鐵圈的人(先手)與其對手(後手)中必定恰有一人,只要他每次都用對自己最有利的方法來移除鐵圈,最後一定百分之百得勝。


















以起始狀態如圖二為例,因為所有鐵圈均不相鄰,故一次只能移除一個鐵圈,先手不管移除哪一個圈,後手只要再移除一個圈,就可以逼迫先手移除最後一個圈,因此後手有百分之百得勝的把握,我們說成『圖二的起始狀態是後手有利』。若起始狀態如圖三就不同了,如果先手懂得先移除相鄰的兩個鐵圈(如2^7 與2^10),就可以迫使後手去移除最後一個圈,因此先手就有百分之百得勝的把握,我們說成『圖三的起始狀態是先手有利』。每一種起始狀態,我們用一個整數來表示它,這個整數就是在該起始狀態中所有被鐵圈圈住的數字總和。例如圖二的起始狀態可以用2^3+2^5+2^11=2088 表示,圖三則可用2^7+2^9+2^10=1664 來表示。
請你寫一個程式來判斷在不同的起始狀態下,到底是先手還是後手有利。
 
解法:
使用 Dynamic Programing,大問題由小問題所組成,大的數字由小的數字組成,故判斷 X 為先手或後手可用 X 的上一層來判斷,若 X 拿走一個鐵圈或拿走兩個鐵圈的狀況都是後手有利,則對 X 本身來說即是先手有利;若都是先手有利,對 X 本身來說則會是後手有利;若前一步有先手後手都有利的情況,則在不會選擇故意輸的條件下,必定是選先手有利。
 
Note:
1. 跳脫出圖形的限制,跟圖形沒有關係。
2. 建一 table,存放各種數字組合所對應的有利選擇,從小到大往後填滿。
3. 預設 table[0] 為先手有利。

//----- user definition -----
#define FIRST 1
#define SECOND 0
#define MAX_NUM 8192-1 //2^13-1
#define BOARD_NUM 13
#define NEIGH_NUM 6


//----- global variables -----
/* a table that records the output and initilize first element to 1 */
int table[MAX_NUM]={1};
int component[BOARD_NUM]; /* bit(board) number */

/* neighbors of each node */
int neighbor[BOARD_NUM][NEIGH_NUM+1]={{2,3,-1,-1,-1,-1,-1},
                      {2,5,-1,-1,-1,-1,-1},
                      {0,1,3,5,6,-1,-1},
                      {0,2,4,6,7,-1,-1},
                      {3,7,-1,-1,-1,-1,-1},
                      {1,2,6,8,9,-1,-1},
                      {2,3,5,7,9,10,-1},
                      {3,4,6,10,11,-1,-1},
                      {5,9,-1,-1,-1,-1,-1},
                      {5,6,8,10,12,-1,-1},
                      {6,7,9,11,12,-1,-1},
                      {7,10,-1,-1,-1,-1,-1},
                      {9,10,-1,-1,-1,-1,-1}};

//----- function prototype -----
int find(int,int); /* return which order is better */
void set_compo(int); /* set up the components of the sum */
/* extract one component of sum,
  if equals 0 then return 1, otherwise return 0 */
int extract(int);

//----- functions -----
/* return which order is better at sum2 */
int find(int sum)
{
 int tmp_sum;

 /* find the output of sum step by step */
 for(tmp_sum=1;tmp_sum<=sum;tmp_sum++)
 {
  /* set up the components of sum */
  set_compo(tmp_sum);

  /* find the output of each tmp_sum */
  table[tmp_sum]=extract(tmp_sum);
 }
 /* return the result output */
 return table[sum];
}

/* store 2^idx if the index is one of the sum's component, otherwise stores 0 */
void set_compo(int sum)
{
 int i,mask=1;
 for(i=0;i<BOARD_NUM;i++,mask*=2)
  component[i]=((mask&sum)==mask)?mask:0;
}

/* return FIRST if table[] is 0 */
/* otherwise return SECOND */
int extract(int sum)
{
 int i,j;
 /* scan all the component array */
 for(i=0;i<BOARD_NUM;i++)
  /* if there is a nonzero in component */
  if(component[i]!=0)
  {
   /* test by extracting one value */
   if(!table[sum-component[i]]) return FIRST;

   /* scan this node's neighbor whether they are combined or not */
   for(j=0;neighbor[i][j]!=-1;j++)
    /* if it is then test by extracting two values */
    if(component[neighbor[i][j]]!=0)
     if(!table[sum-component[i]-component[neighbor[i][j]]])
      return FIRST;
  }
 /* if there's no 0s in table[] then SECOND is better */
 return SECOND;
}

2008年12月13日 星期六

六芒星的束縛

該死的六芒星
周四才弄完圖學程式
怎麼明天又要交六芒星啦
完全沒頭緒 = = 不斷推翻每個想法
到底 dynamic programing 出來的最佳解是什麼!!!!

頭好痛阿!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
不想寫了... i need rest...

2008年12月11日 星期四

陽春小畫家 ver 02

更新:
1.噴槍補強,解決只點一下只會出現一點的問題,亂數公式更新。
2.修正橡皮擦跟噴槍只點一下不拖曳不會有效果的問題。
3.修正線、矩形、三角型、點、噴槍在改變視窗大小之後會消失的問題。

Ps. 似乎有的電腦double buffer反而會閃爍
所以提供single buffer的版本

試用下載 ( single buffer )

試用下載 ( double buffer )

陽春小畫家 ver 01

花了快10個小時弄出來的吧  XD
程式趕在dead line飆出來的感覺真棒
跟大家一起在316研究程式感覺也很棒
越來越有資工系的feel了!!

小畫家下載

可以去載來玩玩
也歡迎提供修改意見 ^^ ~

不過 本人很弱 哈哈 XDDDDDDDD

功能:
1.直線
2.矩形
3.三角形
4.點
5.打字
6.橡皮擦
7.噴槍

2008年12月10日 星期三

Painter 相關運用函數 01

glRasterPos2i( , ); → 繪出的字元位置,參數為(X,Y)座標
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, 'A'); → 畫出字母'A'
shift=glutBitmapWidth(GLUT_BITMAP_9_BY_15, 'A'); → 計算字母'A'的寬度

Note.若要在'A'右邊繼續畫出字母則 X座標 需要加上變數 shift

glColor 系列函數 相關介紹

Note.亂數跑顏色的話需用
glColor3ub( (char)rand()%256 , (char)rand()%256 , (char)rand()%256 );
或是 glColor3b ( rand()%256 , rand()%256 , rand()%256 , 1.0 );

Note. 內建函式庫用 #include < >
自己定義的用 #include " " 要分別compile才會過

Note. 全域變數只有給初始值時不用加 extern 其餘都有,否則會重複定義。

2008年12月9日 星期二

翹課

為了弄無言的歷史報告
第一次翹了電腦視覺的課
翹課是不負責任的表現
對不起謝老師
希望在歷史課能讓我感覺值得
也希望是第一次也是最後一次
想拋開罪惡感

2008年12月8日 星期一

監獄兔 第27話「1階」


Sleepsong - Secret Garden


富士一日本料理

算是三峽這邊少數好吃的店家吧
這周末回去前做了突破去吃了他的饅魚定食
嗯 >///< 鰻魚入口即化 不過我覺得醬汁甜了一點 ^^" 但還是很優啦 小塊的豬排也不錯 茶碗蒸裡面的廖也很實在不會偷工減料 吃的超飽的 滿足 XDDD 從前只吃過天丼、牛丼、親子丼、勝丼跟海苔蛋麵 這次終於做了新突破 XDDD 也沒讓我失望 推薦大家可以去吃 yahoo 生活+ 查的到地址唷 在過小橋直直走過全聯到底右轉的左手邊~~~ ^^

2008年12月6日 星期六

Wishmaster - Nightwish

正常版:


錯誤歌詞搞笑版:


Master!
Apprentice!
Heartborne, 7th Seeker
Warrior!
Disciple!
In me the Wishmaster


Master!
Apprentice!
Heartborne, 7th Seeker
Warrior!
Disciple!
In me the Wishmaster


Elbereth
Lorien


A dreamy-eyed child staring into night
On a journey to storyteller`s mind
Whispers a wish speaks with the stars the words are silent in Him
Distant sigh from a lonely heart
"I`ll be with you soon, my Shalafi"
Grey Havens my destiny


Silvara
Starbreeze


Sla-Mori the one known only by Him
To august realms, the sorcery within
If you hear the call of arcane lore,
Your world shall rest on Earth no more
A maiden elf calling with her cunning song
"Meet me at the Inn of Last Home"
Heartborne will find the way!


Wishmaster
Crusade for Your will
A child, dreamfinder
The Apprentice becoming...

End Of All Hope - Nightwish



It is the end of all hope
To lose the child, the faith
To end all the innocence
To be someone like me
This is the birth of all hope
To have what I once had
This life unforgiven
It will end with a birth

No will to wake for this morn
To see another black rose born
Deathbed is slowly covered with snow
Angels, they fell first but I'm still here
Alone as they are drawing near
In heaven my masterpiece will finally be sung
It is the end of all hope
To lose the child, the faith
To end all the innocence
To be someone like me

Wounded is the deer that leaps highest
And my wound it cuts so deep
Turn off the light and let me pull the plug
It is the end of all hope
To lose the child, the faith
To end all the innocence
To be someone like me
This is the birth of all hope
To have what I once had
This life unforgiven
It will end with a birth

Mandylion without a face
Deathwish without a prayer
End of hope
End of love
End of time
The rest is silence

Mandylion without a face
Deathwish without a prayer
End of hope
End of love
End of time
The rest is silence

It is the end of all hope
To lose the child, the faith
To end all the innocence
To be someone like me
This is the birth of all hope
To have what I once had
It is the end of all hope
To lose the child, the faith
To end all the innocence
To be someone like me
It is the end of all hope
To lose the child, the faith
Oh,end of all hope

Walking In The Air - Nightwish



We're walking in the air
We're floating in the moonlit sky
The people far below are sleeping as we fly

I'm holding very tight
I'm riding in the midnight blue
I'm finding I can fly so high above with you

Far across the world
The villages go by like trees
The rivers and the hills
The forests and the streams
Children gaze open mouth
Taken by surprise
Nobody down below believes their eyes
We're surfing in the air
We're swimming in the frozen sky
We're drifting over icy
Mountains floating by

Suddenly swooping low on an ocean deep
Arousing of a mighty monster from its sleep

We're walking in the air
We're floating in the midnight sky
And everyone who sees us greets us as we fly
I'm holding very tight
I'm riding in the midnight blue
I'm finding I can fly so high above with you

回家

把拔寫了一張單子

1.星期六需倒垃圾。

2.晚上六點燒香、餵魚。

3.星期日中午在家吃火鍋。

4.星期日上午媽媽要帶你到環球買衣服。

5.帶妹妹時多帶一頂安全帽,後附地圖一張。

嗯...很酷,真的在memo後面畫了一張地圖 = =b

啼笑皆非的感覺 XD"... 好像被當成路癡了 呵呵

不過今天太晚回家了

讓奶奶等了一下午,唉,兩邊難做人。

美津濃

剛剛才發現...

原來我家附近的"同鞋會"跟"新運動家"

還有不遠處的"萬岳"都有賣桌球鞋耶!!

要不要衝一個呢 XD"... 科科 還是要拉蔻死呢...

練球


1.左腳站的位置在右腳後面

2.左手抽球引拍靠腳跟腰帶

3.反手切球要多練

4.左手抽球擊球點抓不準

5.練球時要想著自己是左撇子

6.發球要練

7.左手手腕、左腳膝蓋、左腳腳踝痛,修養一天

8.周日晚上練球加油

感謝今天小魚幫忙做專業指導

也凸顯我的教導很差勁

真的會打不會教 不知道該怎麼辦 唉

自己也好久沒專注練球了... 悶悶

加上感冒 今天打球四肢都沒什麼力氣

不開心 = 無言+無奈 ;

return 不開心 ;

2008年12月5日 星期五

魔獸世界: 巫妖電視王 [中文版] Wrath of A Couch Potato

資訊展


成員就跟昨天一樣:Angie、丁、我,
中午在板橋匆匆吃了博多拉麵就火速前往市政府站,( 順帶一提,
味道好重喔吃不習慣 )急到某A連吃藥都忘記了 = =
還好是周四去的,否則若在周末應該完全擠到無法動彈吧!

幫小魚拿了幾家日系相機的DM,可惜沒看到富士的相機,
不懂為啥他只擺了筆電呢,更扯的是沒有國際牌的攤位,超怪!

主打為Angie的筆電,不過應該都大同小異吧,不玩遊戲就用不到獨立顯卡,
也不常看avi等高畫質影片,3D也只是用OpenGL做coding,果然如猜測是依照外觀決定,
反正功能都大同小異,買了日後看了順眼最重要,TOSHIBA M300果然很唯美風,
不適合男人,哈哈,不過配的是獨立顯卡,看來妳要學著打魔獸了 XD?

TOSHIBA熱血的sells還跑進跑出的給我們領貨的地圖,真是太敬業了 m(_ _)m
順便買了一條DDR2-800 2GB的RAM800元,還有一個8GB隨身碟跟外接硬碟的防震包830元,
總共花了1,630元,還有相機的電池跟SD卡要買,繼續使用老相機 XD"...撐住阿
雖然你是四年多前的水貨 哈哈!

可惜的是沒幫詠寧拿到包子槌,實在太多人排隊了,去了第一次是暫停排隊,
第二次再去就變成本日排隊已結束,太扯,比扯鈴還扯,
還好有拿到TOSHIBA的PaLa Chan娃娃,超可愛的啦 >///<
沒拿到包子槌也沒有即時趕回去開店,感謝詠寧幫我顧了一晚,獻上Mister Donuts表達感激,
吃胖一點吧 哈哈哈!

資訊展撈到不錯的東西,明天希望小魚去也有收穫,
買了筆電專題加油,難得為妳做些什麼,好好努力,
雖然我今天那份papper看起來就跟天書一樣 唉 ~"~... 無奈阿
明天計組... 想把極地長征看完 XDDDDDDDDDDDDD

2008年12月4日 星期四

忙裡偷閒


非法警戒 ( PRIDE AND GLORY )

預告片 電影介紹

跟一般的警匪片不同,看完覺得是值得深思的一部片,除了開頭有點鬆散,以及 typical American movie 裡面很"fucking"出現之外,大致上都很棒,沒有過多的動作也沒有過多的華麗畫面麻痺觀眾視覺,就是能讓人看了感觸很深,不禁思索,面對名利、財富,良知還剩下多少?是否在追逐這一切的時候,反而忽略了當初的動機?幾個簡單的問題,卻難以肯定的回答。是一部值得一看的電影。




忙裡偷閒,考完試都沒有鬆一口氣的感覺,放下一切喘口氣去偷偷看了場電影,
也去吃了很久沒吃的古拉爵,或許是我口味重,覺得很好吃啦,尤其是最後的飲料超優,
不過今天是個特別的日子吧,站在固定某個位置的服務生都會打翻或打破東西,
天阿!有神快拜!

另外有兩部預告片也不錯"畫皮",經典對白:原來我們都是妖精!
XDDD  不知道為啥看到這句覺得很好笑!
雷霆戰狗",狗狗超可愛的啦,尤其是最後花栗鼠說要去擰斷警衛脖子,
實在是太可愛了 >"<  好想看喔  呵呵  有機會再揪團去看。

2008年12月2日 星期二

Simulation: The Tortoise and the Hare

1.格子 1 ~ 70
2.起始位置為 1
3.每秒動一回合,先到達或超過 70 者算贏。
4.若是位置在 1 仍往後則為 1
5.烏龜位置用"T"表示;兔子位置用"H"表示;重疊則用"OUCH!!!"表示
6.一開始要印出 "BANG !!!!!"
"AND THEY'RE OFF !!!!!"
7.烏龜贏印出"TORTOISE WINS!!! YAY!!!";兔子贏印出"HARE WINS!!! YAY!!!"
8.若是同時到達終點則算是烏龜贏
9.烏龜跟兔子的步伐如下:






/* Simulation: The Tortoise and the Hare */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* function prototypes */
void moveTortoise( int *turtlePtr );
void moveHare( int *rabbitPtr );
void printCurrentPositions( int *snapperPtr, int *bunnyPtr );

/* tutle and rabbit movements */
int T_move[10]={3,3,3,3,3,-6,-6,1,1,1};
int H_move[10]={0,0,9,9,-12,1,1,1,2,2};

int main()
{
srand((unsigned)time(NULL));

/* set up the initial position */
int T_square=1,H_square=1,i;

for( ; T_square<70&&H_square<70 ; )
{
/* delay 1 second per round */
clock_t start_time;
start_time = clock();
while((clock() - start_time) < 1 * CLOCKS_PER_SEC){}

  /* move and show real-time condition */
moveTortoise(&T_square);
moveHare(&H_square);
printCurrentPositions(&T_square,&H_square);
}

 /* determine who's winner */
(T_square>=70)?printf("TORTOISE WINS!!! YAY!!!\n"):printf("HARE WINS!!! YAY!!!\n");

system("PAUSE");
return 0;
}

void moveTortoise( int *turtlePtr )
{
*turtlePtr+=T_move[rand()%10];
if(*turtlePtr<=0)
*turtlePtr=1;
}

void moveHare( int *rabbitPtr )
{
*rabbitPtr+=H_move[rand()%10];
if(*rabbitPtr<=0)
*rabbitPtr=1;
}

void printCurrentPositions( int *snapperPtr, int *bunnyPtr )
{
/* redraw thw competition */
system("CLS");
printf("BANG !!!!!\n");
printf("AND THEY'RE OFF !!!!!\n");
int i;
printf(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
for(i=1;i<=80;i++)
{
if(i==*snapperPtr&&i==*bunnyPtr)
{
printf("OUCH!!!");
i+=6;
}
else if(i==*snapperPtr)
printf("T");
else if(i==*bunnyPtr)
printf("H");
else
printf(" ");
}
printf(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
}

延遲 1 秒的迴圈

// CLOCKS_PER_SEC 常為 1000 (ms)
clock_t start_time;
start_time = clock();
while((clock() - start_time) < 1 * CLOCKS_PER_SEC){}

2008年12月1日 星期一

Knight's Tour using non-recursive programing


解法:

騎士的走法,基本上可以使用遞迴來解決,但是純綷的遞迴在維度大時相當沒有效率,一個聰明的解法由J.C. Warnsdorff在1823年提出,簡單的說,先將最難的位置走完,接下來的路就寬廣了,騎士所要走的下一步,「為下一步再選擇時,所能走的步數最少 的一步。」,使用這個方法,在不使用遞迴的情況下,可以有較高的機率找出走法(找不到走法的機會也是有的)。

演算法:

for (step = 1; step < 總格數 ; step++)
{
測試下一步可以走的八個方向,並記錄下步可走的格數。

if ( 下步可走格數 == 0 )
{
return 0;
}
else if ( 可走格數 == 1 )
{
下一步只有一種可能
}
else
{
重複 if 內容找出下一步的下一步可走的最少格來走,藉此提升行走效率,
如果計算到最少格有相同者,則選第一順位來走。
}
檢查stack,找出最少出路的那一步,並replace騎士的位置,
再下一個for loop則由此新位置來走。
}

//----------------------------------------------------------------------------------------------
//若是8*8的棋盤,其中 (5,4) 這點無解
程式碼:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define col_size 8
#define row_size 8

typedef struct NextMove
{
int i;
int j;
}NextMove;

void clear();
int knight(int,int);

int checker[row_size+4][col_size+4];
int step=0;
int ans=0;

// Knight's directions in X-axis and Y-axis.
const int horizontal[8]={ 2, 1,-1,-2,-2,-1, 1, 2};
const int vertical[8]={-1,-2,-2,-1, 1, 2, 2, 1};

NextMove next[row_size];

int main()
{
time_t ticks1,ticks2;
int i,j,p,t;
clear();

ticks1 = time(NULL);

for(p=2;p<row_size+2;p++)
for(t=2;t<col_size+2;t++)
{
clear();
if(knight(p,t)!=0)
{
printf("\nAns : %d\tStep : %d\n",++ans,step);
for(i=2;i<row_size+2;i++)
{
for(j=2;j<col_size+2;j++)
printf("%3d",checker[i][j]);
printf("\n");
}
}
}

ticks2 = time(NULL);

printf("\nStart time : %.24s\r\n",ctime(&ticks1));
printf(" End time : %.24s\r\n",ctime(&ticks2));

system("PAUSE");
return 0;
}

// To avoid that the knight goes out of range.
void clear()
{
int i,j;
for(i=0;i<row_size+4;i++)
for(j=0;j<col_size+4;j++)
if(i<2||i>row_size+1||j<2||j>col_size+1)
checker[i][j]=-1;
else
checker[i][j]=0;
step=0;
}

// Find the path.
int knight(int i,int j)
{
int p,t,k,temp,count;
int temp_i,temp_j,min_way,second_way[row_size];

 // Clear the next step stack
for(p=0;p<8;p++)
{
next[p].i=0;
next[p].j=0;
}

checker[i][j]=1;

for(p=1;p<row_size*col_size;p++)
{
// Clear the number of ways of each next step
for(t=0;t<8;t++)
second_way[t]=0;

  // Reset index "count"
count=0;

  // Try the eight directions
for(k=0;k<8;k++)
{
temp_i=i+vertical[k];
temp_j=j+horizontal[k];

// If the direction is passable then set up the knight,
   // and ways counting++
if(checker[temp_i][temp_j]==0)
{
next[count].i=temp_i;
next[count++].j=temp_j;
}
}

 // After trying the eight directions
  // If no ways can move
if(count==0)
return 0;
// If just one way can move then thw way is the smallest-step way
else if(count==1)
// Thw direction was pushed in next[0]
min_way=0;
// Otherwise find the smallest ways of the next ways,
  // if we got the same ways then choose the first one.
else
{
// Find the ways of each next-step way
for(t=0;t<count;t++)
// Try the eight directions like before
for(k=0;k<8;k++)
{
temp_i=next[t].i+vertical[k];
temp_j=next[t].j+horizontal[k];

if(checker[temp_i][temp_j]==0)
second_way[t]++;
}

temp=second_way[0];
min_way=0;

   // Search for the smallest ways of each next-step way
for(t=1;t<count;t++)
if(second_way[t]<temp)
{
temp=second_way[t];
min_way=t;
}
}

  // Find out the smallest ways of the next step
i=next[min_way].i;
j=next[min_way].j;
checker[i][j]=p+1;
}

step=p;
return 1;
}

OpenCV on VC 2005 Express

What Is OpenCV?
OpenCV [OpenCV] is an open source (see http://opensource.org) computer vision library available from http://SourceForge.net/projects/opencvlibrary. The library is written in C and C++ and runs under Linux, Windows and Mac OS X. There is active development on interfaces for Python, Ruby, Matlab, and other languages.

OpenCV Source 下載

因為我裝的是 Visual Studio 2005 Express

其中的 Platform SDK 要另外載 通常搜尋到的是 2003 及 2008

SDK for 2005 版本下載

VC 2005 下安裝與配置

不過想從 Borland C 入手... 還在找Crack