Board logo

標題: d212: 東東爬階梯 [打印本頁]

作者: buy    時間: 2010-11-6 10:19     標題: d212: 東東爬階梯

內容 : 正體->简体


東東有個嗜好,爬階梯不是一次走一階,就是一次走兩階。

換句話說,假設階梯有三階,那他有三種走法

一:第一步走一階,第二步走二階。

二:第一步走二階,第二步走一階。

三:全程都走一階。

這題要問你,假設階梯有n階,那東東有幾種走法?

輸入說明 :


第一行有一個正整數n,0<n<100,表示階梯有n階。

輸出說明 :


請輸出n個階梯有幾種走法。
範例輸入 :

若題目沒有特別說明,則應該以多測資的方式讀取,若不知如何讀取請參考 a001 的範例程式。1
2
5
範例輸出 :

1
2
8

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

http://zerojudge.tw/ShowProblem?problemid=d212

============================================
作者: buy    時間: 2010-11-6 10:21

  1.         string s[100];

  2.         s[ 1] = "1"; s[ 2] = "2"; s[ 3] = "3"; s[ 4] = "5"; s[ 5] = "8"; s[ 6] = "13"; s[ 7] = "21"; s[ 8] = "34"; s[ 9] = "55"; s[10] = "89";
  3.         s[11] = "144"; s[12] = "233"; s[13] = "377"; s[14] = "610"; s[15] = "987"; s[16] = "1597"; s[17] = "2584"; s[18] = "4181"; s[19] = "6765"; s[20] = "10946";
  4.         s[21] = "17711"; s[22] = "28657"; s[23] = "46368"; s[24] = "75025"; s[25] = "121393"; s[26] = "196418"; s[27] = "317811"; s[28] = "514229"; s[29] = "832040"; s[30] = "1346269";
  5.         s[31] = "2178309"; s[32] = "3524578"; s[33] = "5702887"; s[34] = "9227465"; s[35] = "14930352"; s[36] = "24157817"; s[37] = "39088169"; s[38] = "63245986"; s[39] = "102334155"; s[40] = "165580141";
  6.         s[41] = "267914296"; s[42] = "433494437"; s[43] = "701408733"; s[44] = "1134903170"; s[45] = "1836311903"; s[46] = "2971215073"; s[47] = "4807526976"; s[48] = "7778742049"; s[49] = "12586269025"; s[50] = "20365011074";
  7.         s[51] = "32951280099"; s[52] = "53316291173"; s[53] = "86267571272"; s[54] = "139583862445"; s[55] = "225851433717"; s[56] = "365435296162"; s[57] = "591286729879"; s[58] = "956722026041"; s[59] = "1548008755920"; s[60] = "2504730781961";
  8.         s[61] = "4052739537881"; s[62] = "6557470319842"; s[63] = "10610209857723"; s[64] = "17167680177565"; s[65] = "27777890035288"; s[66] = "44945570212853"; s[67] = "72723460248141"; s[68] = "117669030460994"; s[69] = "190392490709135"; s[70] = "308061521170129";
  9.         s[71] = "498454011879264"; s[72] = "806515533049393"; s[73] = "1304969544928657"; s[74] = "2111485077978050"; s[75] = "3416454622906707"; s[76] = "5527939700884757"; s[77] = "8944394323791464"; s[78] = "14472334024676221"; s[79] = "23416728348467685"; s[80] = "37889062373143906";
  10.         s[81] = "61305790721611591"; s[82] = "99194853094755497"; s[83] = "160500643816367088"; s[84] = "259695496911122585"; s[85] = "420196140727489673"; s[86] = "679891637638612258"; s[87] = "1100087778366101931"; s[88] = "1779979416004714189"; s[89] = "2880067194370816120"; s[90] = "4660046610375530309";
  11.         s[91] = "7540113804746346429"; s[92] = "12200160415121876738"; s[93] = "19740274219868223167"; s[94] = "31940434634990099905"; s[95] = "51680708854858323072"; s[96] = "83621143489848422977"; s[97] = "135301852344706746049"; s[98] = "218922995834555169026"; s[99] = "354224848179261915075";
複製代碼

作者: chuangjoy    時間: 2010-11-6 10:26

  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4.    
  5.     string s[100];
  6.     int n;
  7.    
  8.     s[ 1] = "1"; s[ 2] = "2"; s[ 3] = "3"; s[ 4] = "5"; s[ 5] = "8"; s[ 6] = "13"; s[ 7] = "21"; s[ 8] = "34"; s[ 9] = "55"; s[10] = "89";
  9.     s[11] = "144"; s[12] = "233"; s[13] = "377"; s[14] = "610"; s[15] = "987"; s[16] = "1597"; s[17] = "2584"; s[18] = "4181"; s[19] = "6765"; s[20] = "10946";
  10.     s[21] = "17711"; s[22] = "28657"; s[23] = "46368"; s[24] = "75025"; s[25] = "121393"; s[26] = "196418"; s[27] = "317811"; s[28] = "514229"; s[29] = "832040"; s[30] = "1346269";
  11.     s[31] = "2178309"; s[32] = "3524578"; s[33] = "5702887"; s[34] = "9227465"; s[35] = "14930352"; s[36] = "24157817"; s[37] = "39088169"; s[38] = "63245986"; s[39] = "102334155"; s[40] = "165580141";
  12.     s[41] = "267914296"; s[42] = "433494437"; s[43] = "701408733"; s[44] = "1134903170"; s[45] = "1836311903"; s[46] = "2971215073"; s[47] = "4807526976"; s[48] = "7778742049"; s[49] = "12586269025"; s[50] = "20365011074";
  13.     s[51] = "32951280099"; s[52] = "53316291173"; s[53] = "86267571272"; s[54] = "139583862445"; s[55] = "225851433717"; s[56] = "365435296162"; s[57] = "591286729879"; s[58] = "956722026041"; s[59] = "1548008755920"; s[60] = "2504730781961";
  14.     s[61] = "4052739537881"; s[62] = "6557470319842"; s[63] = "10610209857723"; s[64] = "17167680177565"; s[65] = "27777890035288"; s[66] = "44945570212853"; s[67] = "72723460248141"; s[68] = "117669030460994"; s[69] = "190392490709135"; s[70] = "308061521170129";
  15.     s[71] = "498454011879264"; s[72] = "806515533049393"; s[73] = "1304969544928657"; s[74] = "2111485077978050"; s[75] = "3416454622906707"; s[76] = "5527939700884757"; s[77] = "8944394323791464"; s[78] = "14472334024676221"; s[79] = "23416728348467685"; s[80] = "37889062373143906";
  16.     s[81] = "61305790721611591"; s[82] = "99194853094755497"; s[83] = "160500643816367088"; s[84] = "259695496911122585"; s[85] = "420196140727489673"; s[86] = "679891637638612258"; s[87] = "1100087778366101931"; s[88] = "1779979416004714189"; s[89] = "2880067194370816120"; s[90] = "4660046610375530309";
  17.     s[91] = "7540113804746346429"; s[92] = "12200160415121876738"; s[93] = "19740274219868223167"; s[94] = "31940434634990099905"; s[95] = "51680708854858323072"; s[96] = "83621143489848422977"; s[97] = "135301852344706746049"; s[98] = "218922995834555169026"; s[99] = "354224848179261915075";
  18.    
  19.     while(cin >> n){
  20.             cout << s[n] <<endl;
  21.     }
  22.    
  23. return 0;
  24. }
複製代碼

作者: Alen    時間: 2010-11-6 10:28

  1. #include<iostream>
  2. using namespace std;
  3. int main(void){

  4.             string s[100];

  5.         s[ 1] = "1"; s[ 2] = "2"; s[ 3] = "3"; s[ 4] = "5"; s[ 5] = "8"; s[ 6] = "13"; s[ 7] = "21"; s[ 8] = "34"; s[ 9] = "55"; s[10] = "89";
  6.         s[11] = "144"; s[12] = "233"; s[13] = "377"; s[14] = "610"; s[15] = "987"; s[16] = "1597"; s[17] = "2584"; s[18] = "4181"; s[19] = "6765"; s[20] = "10946";
  7.         s[21] = "17711"; s[22] = "28657"; s[23] = "46368"; s[24] = "75025"; s[25] = "121393"; s[26] = "196418"; s[27] = "317811"; s[28] = "514229"; s[29] = "832040"; s[30] = "1346269";
  8.         s[31] = "2178309"; s[32] = "3524578"; s[33] = "5702887"; s[34] = "9227465"; s[35] = "14930352"; s[36] = "24157817"; s[37] = "39088169"; s[38] = "63245986"; s[39] = "102334155"; s[40] = "165580141";
  9.         s[41] = "267914296"; s[42] = "433494437"; s[43] = "701408733"; s[44] = "1134903170"; s[45] = "1836311903"; s[46] = "2971215073"; s[47] = "4807526976"; s[48] = "7778742049"; s[49] = "12586269025"; s[50] = "20365011074";
  10.         s[51] = "32951280099"; s[52] = "53316291173"; s[53] = "86267571272"; s[54] = "139583862445"; s[55] = "225851433717"; s[56] = "365435296162"; s[57] = "591286729879"; s[58] = "956722026041"; s[59] = "1548008755920"; s[60] = "2504730781961";
  11.         s[61] = "4052739537881"; s[62] = "6557470319842"; s[63] = "10610209857723"; s[64] = "17167680177565"; s[65] = "27777890035288"; s[66] = "44945570212853"; s[67] = "72723460248141"; s[68] = "117669030460994"; s[69] = "190392490709135"; s[70] = "308061521170129";
  12.         s[71] = "498454011879264"; s[72] = "806515533049393"; s[73] = "1304969544928657"; s[74] = "2111485077978050"; s[75] = "3416454622906707"; s[76] = "5527939700884757"; s[77] = "8944394323791464"; s[78] = "14472334024676221"; s[79] = "23416728348467685"; s[80] = "37889062373143906";
  13.         s[81] = "61305790721611591"; s[82] = "99194853094755497"; s[83] = "160500643816367088"; s[84] = "259695496911122585"; s[85] = "420196140727489673"; s[86] = "679891637638612258"; s[87] = "1100087778366101931"; s[88] = "1779979416004714189"; s[89] = "2880067194370816120"; s[90] = "4660046610375530309";
  14.         s[91] = "7540113804746346429"; s[92] = "12200160415121876738"; s[93] = "19740274219868223167"; s[94] = "31940434634990099905"; s[95] = "51680708854858323072"; s[96] = "83621143489848422977"; s[97] = "135301852344706746049"; s[98] = "218922995834555169026"; s[99] = "354224848179261915075";

  15.         int a = 0;
  16.         
  17.         while (cin >> a){
  18.               cout << s[a] << endl;      
  19.         }


  20. //system("pause");
  21. return 0;
  22. }
複製代碼

作者: p17johnny    時間: 2010-11-6 10:34

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main(void){
  5.    
  6.     string s[100];
  7.     int n;
  8.    
  9.     s[ 1] = "1"; s[ 2] = "2"; s[ 3] = "3"; s[ 4] = "5"; s[ 5] = "8"; s[ 6] = "13"; s[ 7] = "21"; s[ 8] = "34"; s[ 9] = "55"; s[10] = "89";
  10.     s[11] = "144"; s[12] = "233"; s[13] = "377"; s[14] = "610"; s[15] = "987"; s[16] = "1597"; s[17] = "2584"; s[18] = "4181"; s[19] = "6765"; s[20] = "10946";
  11.     s[21] = "17711"; s[22] = "28657"; s[23] = "46368"; s[24] = "75025"; s[25] = "121393"; s[26] = "196418"; s[27] = "317811"; s[28] = "514229"; s[29] = "832040"; s[30] = "1346269";
  12.     s[31] = "2178309"; s[32] = "3524578"; s[33] = "5702887"; s[34] = "9227465"; s[35] = "14930352"; s[36] = "24157817"; s[37] = "39088169"; s[38] = "63245986"; s[39] = "102334155"; s[40] = "165580141";
  13.     s[41] = "267914296"; s[42] = "433494437"; s[43] = "701408733"; s[44] = "1134903170"; s[45] = "1836311903"; s[46] = "2971215073"; s[47] = "4807526976"; s[48] = "7778742049"; s[49] = "12586269025"; s[50] = "20365011074";
  14.     s[51] = "32951280099"; s[52] = "53316291173"; s[53] = "86267571272"; s[54] = "139583862445"; s[55] = "225851433717"; s[56] = "365435296162"; s[57] = "591286729879"; s[58] = "956722026041"; s[59] = "1548008755920"; s[60] = "2504730781961";
  15.     s[61] = "4052739537881"; s[62] = "6557470319842"; s[63] = "10610209857723"; s[64] = "17167680177565"; s[65] = "27777890035288"; s[66] = "44945570212853"; s[67] = "72723460248141"; s[68] = "117669030460994"; s[69] = "190392490709135"; s[70] = "308061521170129";
  16.     s[71] = "498454011879264"; s[72] = "806515533049393"; s[73] = "1304969544928657"; s[74] = "2111485077978050"; s[75] = "3416454622906707"; s[76] = "5527939700884757"; s[77] = "8944394323791464"; s[78] = "14472334024676221"; s[79] = "23416728348467685"; s[80] = "37889062373143906";
  17.     s[81] = "61305790721611591"; s[82] = "99194853094755497"; s[83] = "160500643816367088"; s[84] = "259695496911122585"; s[85] = "420196140727489673"; s[86] = "679891637638612258"; s[87] = "1100087778366101931"; s[88] = "1779979416004714189"; s[89] = "2880067194370816120"; s[90] = "4660046610375530309";
  18.     s[91] = "7540113804746346429"; s[92] = "12200160415121876738"; s[93] = "19740274219868223167"; s[94] = "31940434634990099905"; s[95] = "51680708854858323072"; s[96] = "83621143489848422977"; s[97] = "135301852344706746049"; s[98] = "218922995834555169026"; s[99] = "354224848179261915075";
  19.    
  20.     while(cin >> n){
  21.             cout << s[n] <<endl;
  22.     }
  23.    
  24. return 0;
  25. }
複製代碼

作者: b1081081    時間: 2010-11-13 10:23

  1. #include<iostream>

  2. using namespace std;

  3. int main(void){



  4.             string s[100];



  5.         s[ 1] = "1"; s[ 2] = "2"; s[ 3] = "3"; s[ 4] = "5"; s[ 5] = "8"; s[ 6] = "13"; s[ 7] = "21"; s[ 8] = "34"; s[ 9] = "55"; s[10] = "89";

  6.         s[11] = "144"; s[12] = "233"; s[13] = "377"; s[14] = "610"; s[15] = "987"; s[16] = "1597"; s[17] = "2584"; s[18] = "4181"; s[19] = "6765"; s[20] = "10946";

  7.         s[21] = "17711"; s[22] = "28657"; s[23] = "46368"; s[24] = "75025"; s[25] = "121393"; s[26] = "196418"; s[27] = "317811"; s[28] = "514229"; s[29] = "832040"; s[30] = "1346269";

  8.         s[31] = "2178309"; s[32] = "3524578"; s[33] = "5702887"; s[34] = "9227465"; s[35] = "14930352"; s[36] = "24157817"; s[37] = "39088169"; s[38] = "63245986"; s[39] = "102334155"; s[40] = "165580141";

  9.         s[41] = "267914296"; s[42] = "433494437"; s[43] = "701408733"; s[44] = "1134903170"; s[45] = "1836311903"; s[46] = "2971215073"; s[47] = "4807526976"; s[48] = "7778742049"; s[49] = "12586269025"; s[50] = "20365011074";

  10.         s[51] = "32951280099"; s[52] = "53316291173"; s[53] = "86267571272"; s[54] = "139583862445"; s[55] = "225851433717"; s[56] = "365435296162"; s[57] = "591286729879"; s[58] = "956722026041"; s[59] = "1548008755920"; s[60] = "2504730781961";

  11.         s[61] = "4052739537881"; s[62] = "6557470319842"; s[63] = "10610209857723"; s[64] = "17167680177565"; s[65] = "27777890035288"; s[66] = "44945570212853"; s[67] = "72723460248141"; s[68] = "117669030460994"; s[69] = "190392490709135"; s[70] = "308061521170129";

  12.         s[71] = "498454011879264"; s[72] = "806515533049393"; s[73] = "1304969544928657"; s[74] = "2111485077978050"; s[75] = "3416454622906707"; s[76] = "5527939700884757"; s[77] = "8944394323791464"; s[78] = "14472334024676221"; s[79] = "23416728348467685"; s[80] = "37889062373143906";

  13.         s[81] = "61305790721611591"; s[82] = "99194853094755497"; s[83] = "160500643816367088"; s[84] = "259695496911122585"; s[85] = "420196140727489673"; s[86] = "679891637638612258"; s[87] = "1100087778366101931"; s[88] = "1779979416004714189"; s[89] = "2880067194370816120"; s[90] = "4660046610375530309";

  14.         s[91] = "7540113804746346429"; s[92] = "12200160415121876738"; s[93] = "19740274219868223167"; s[94] = "31940434634990099905"; s[95] = "51680708854858323072"; s[96] = "83621143489848422977"; s[97] = "135301852344706746049"; s[98] = "218922995834555169026"; s[99] = "354224848179261915075";



  15.         int a = 0;

  16.         

  17.         while (cin >> a){

  18.               cout << s[a] << endl;      

  19.         }





  20. //system("pause");

  21. return 0;

  22. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2