TopCoder

YenSean
Hello World!

User's AC Ratio

67.2% (43/64)

Submission's AC Ratio

12.5% (70/559)

Tags

Description

有三堆石頭,個數分別為10個、15個、20個,由二人輪流取石頭,取的時候只能從其中一堆取,至少取一個,至多取全部,如此玩到最後一堆,拿完最後一個的人輸。請設計一程式讓電腦與Judge端程式對玩,獲得勝利。

本題為互動題,請引入"lib1087.h"

可以使用的函式:


  • void Initialize():初始化三堆石頭,請務必在開始拿石頭之前呼叫它。

  • void Take_Stone(int pile_no, int num, int *com_pile, int *com_num):從第pile_no(只能是1,2或3)堆拿取num個石頭,接著輪到電腦取石頭,電腦取石頭的動作會儲存於*com_pile 以及 *com_num 當中,分別代表第幾堆以及拿幾個。你可以假設電腦的取石頭動作都是合法的。


你不能在同一堆拿取過多的石頭,否則不可能AC。
當你強迫Judge端程式拿走最後一顆石頭時,Judge會自動結束你的程式。


※你可以從這裡下載測試用的中繼檔,編譯時請連同該檔案一起編譯即可。
編譯指令範例:g++ 1087.c 1087_stone.o -o 1087

Input Format

本題沒有Input。請不要從螢幕或檔案輸入任何東西。

Output Format

本題沒有Output。

※測試用的程式會輸出兩邊對戰的過程至stone.log。

Sample Input 1

Sample Output 1

※stone.log檔案內容範例1:
=> 5 10 15
You took 15 from PILE 3.
=> 5 10 0
I took 10 from PILE 2.
=> 5 0 0
You took 4 from PILE 1.
=> 1 0 0
I took 1 from PILE 1.

You WIN.

※stone.log檔案內容範例2:
=> 5 10 15
You took 16 from PILE 1.

ERROR!
You took too much.

Hints

一個不保證AC的範例程式:

#include "lib1087.h"

int main(void)
{
 int MyPile[3]={10,15,20},running=1,i,j,k;
 Initialize();
 while(running)
 {
  for(i=0;i<3;i++)
   if(MyPile[i]>0)
   {
    Take_Stone(i+1,MyPile[i],&j,&k);
    MyPile[j-1]-=k;
   }
 }
 return 0;
}


Problem Source

原TIOJ1087 / 94建中校內資訊能力競賽(prob 5)

Subtasks

No. Testdata Range Score
1 0 50
2 1 50

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 262144 1
1 1000 65536 262144 2