The monkey divide the peach Two by the way of recursion

Source: Internet
Author: User
<span style= "FONT-SIZE:18PX;" >package Lianx;


public class Monkeytao {


	static int ts=0;//peach Total
    int fs=1;//record number of times
    static int hs=5;//Monkey number ...
    The range of the number of peaches in int tsscope=5000;//. Too big to overflow.
    public int FT (int t) {
        if (t==tsscope) {
            //) cancels recursive
            System.out.println ("End") when the peach number is the largest range of values;
           return 0;
        } else{
            if ((t-1)%hs==0 && fs <=hs) {
                if (fs==hs) {
                    System.out.println ("Peach number =" +ts + "satisfies the peach condition"); c14/>}
                fs+=1;
                Return ft ((t-1)/5*4); Back to the monkey to take away a copy of the remaining total
            }else{
                //
               The number of times that did not meet the condition fs=1;//score was reset to 1 returns
               ft (ts+=1);// Peaches number plus +1}} public
    static void Main (string[] args) {
        new Monkeytao (). FT (0);
    }
} </span>


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.