sicily-1029 Rabbit

Source: Internet
Author: User

A Test instructions (0.04s)

Each pair of mature rabbits can have a pair of rabbits, rabbits mature after m months, assuming the rabbit will not die, calculate the total number of rabbits after D months.

Two To high-precision addition (with string)

Three Formula: Ans[m] = ans[m-1] + ans[m-m].

The M maximum can only be 10, so open an array with a maximum of 10 strings. The group that divides 1 to n into a number of M, reuses the data inside the array to save space.

Four Source

    

1 //2 //main.cpp3 //sicily-10294 //5 //Created by Ashley on 14-12-5.6 //Copyright (c) 2014 Ashley. All rights reserved.7 //8 9#include <iostream>Ten#include <string> One using namespacestd; A stringans[Ten]; - stringClearzeros (stringdata) - { the     if(data[0] =='0') { -         intKey = (int) Data.length ()-1; -          for(inti =0; I < data.length (); i++) { -             if(Data[i]! ='0') { +Key =i; -                  Break; +             } A         } atData.erase (0, key); -     } -     if(Data = ="") { -data ="0"; -     } -     returndata; in } -  to //Bitwise Operation + voidCountpoint (string&operand1,string&operand2) - { the      while(Operand1.length () <operand2.length ()) { *Operand1 ="0"+Operand1; $     }Panax Notoginseng      while(Operand1.length () >operand2.length ()) { -Operand2 ="0"+Operand2; the     } + } A  the stringAddition (stringAddent,stringadder) + { -     //the first bit, addend and summand in front of the appropriate 0, so that they contain the same number of digits $ countpoint (addent, adder); $     //One more 0, OK and the maximum number of digits -Addent ="0"+addent; -Adder ="0"+adder; the     //starting from the low, the corresponding bits are added, the results are written into the summand, if there is a carry, directly to summand the previous one plus 1 -      for(inti = (int) Addent.length ()-1; i >0; i--) {WuyiAddent[i] = Addent[i] + adder[i]- -; the         if(Addent[i] >'9') { -Addent[i] = addent[i]-Ten; WuAddent[i-1] = Addent[i-1] +1; -         } About     } $     returnClearzeros (addent); - } -  - intMainintargcConst Char*argv[]) A { +     intmonth, Deadline; the      while(Cin >> Month >>deadline) { -         if(Month = =0&& deadline = =0) { $              Break; the         } the         stringincrement; theincrement ="1"; theans[0] ="1"; -          for(inti =1; I <= month-1; i++) { inAns[i] = addition (Ans[i-1], increment); the         } the          for(inti = month; I <= deadline; i++) { Aboutincrement = ans[i%month]; theAns[i% Month] = addition (ans[(I-1) %month], increment); the         } thecout << ans[deadline% month] <<Endl; +     } -     return 0; the}

sicily-1029 Rabbit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.