compute the hight of utopianTree

    private static final int ONE_YEAR_GROWTH_SUMMER_FACTOR=1;
    private static final int UTOPIANTREE_INITIALIZE_HEIGHT=1;
        /**
         * compute the hight of utopianTree
         * return hight: hight
         * parameter src n cycles: 0<= n <=60
         * 	1 year has 2 cycles :
         * 		spring get double meters height
         * 		summer get 1 meter height
         *
         * constraints:
         *  test cases:
         * 		1<= t <= 10
         *  cycles :
         *      0<= n <= 60
         *
         *  constraint height : initialize height 1 meter
         *
         *    Period  Height
         0          1
         1          2
         2          3
         3          6
         4          7
         5          14

         * @param srcNumCycle
         * @return
         */
        public static int utopianTree(int srcNumCycle) {
            if(srcNumCycle < 0 || srcNumCycle > 60){
                return 0;
            }
            int retVal=srcNumCycle%2;
            int yearTemp=srcNumCycle/2;
            int sumTotalHeight=UTOPIANTREE_INITIALIZE_HEIGHT;
            int plusFactorEvenSpring=0;
            int plusFactorEvenSummer=ONE_YEAR_GROWTH_SUMMER_FACTOR;
            int plusFactorOddSpring=0;
            int plusFactorOddSummer=ONE_YEAR_GROWTH_SUMMER_FACTOR;
            int plusFactorEven=0;
            int count=0;
            while(true){
                if(retVal==0){
                    int countEven=0;
                    while(true){
                        plusFactorEvenSpring=sumTotalHeight*2;
                        plusFactorEven=plusFactorEvenSpring+plusFactorEvenSummer;
                        sumTotalHeight+=plusFactorEven;
                        countEven++;
                        if(countEven>yearTemp){
                            break;
                        }
                    }
                }else{
                    int countOddEven=0;
                    while(true){
                        plusFactorOddSpring=sumTotalHeight*2;
                        int plusFactorOdd=plusFactorOddSpring+plusFactorOddSummer;
                        sumTotalHeight+=plusFactorOdd;
                        countOddEven++;
                        if(countOddEven>yearTemp){
                            break;
                        }
                    }
                    plusFactorOddSpring=sumTotalHeight*2;
                    sumTotalHeight+=plusFactorOddSpring;
                }
                int yearCount=0;
                if(retVal==0){
                    yearCount=yearTemp;
                }else{
                    yearCount=yearTemp+1;
                }
                count++;
                if(count>yearCount){
                    break;
                }
            }
            return sumTotalHeight;
        }

#打工人的工作餐日常##我在牛爱网找对象##职业发展规划如何回答##面试等了一周没回复,还有戏吗#
全部评论

相关推荐

点赞 评论 收藏
分享
03-24 17:55
已编辑
中南大学 Java
被闪击了,qwq刚吃完饭还没出食堂,一个山东的电话打过来,我还寻思没有投山东的公司。然后问我现在有没有空,然后就开始面了##&nbsp;3.24上来先是自我介绍,然后先问的项目相关1.第一个项目用了SpringCloud,有用什么注册中心来做模块间的信息传递我只用了RocketMQ,所以就说了消息队列2.第二个项目用了Nacos,怎么用的只把Nacos作为了注册中心,因为没什么配置要用到nacos,就一个spi对应的资源3.看我项目用到了Redis,怎么用的就是当作缓存,缓解Mysql压力然后就小问了一下八股,介于煮啵最近在看项目相关八股,然后基础答得稀碎4.==&nbsp;与&nbsp;equals()&nbsp;区别差点答反了,而且说的确实模棱两可5.关键字final的用法煮啵只用过类和变量上的final,忘了方法也可以,被提醒了,类答的就是string类就是final的6.刚刚你提到了string,String、StringBuffer、StringBuilder的区别String不可变然后把StringBuffer是线程安全和StringBuilder不安全搞反了,寄寄7.然后问Mysql的底层数据结构我又没想起来,然后人家提醒是b+淦嘞,我记起来索引是用的b+,忘了mysql也是8.然后问我用没用过mybatis和mybatisplus我说用过然后就结束了,到反问环节了1.这后面还有面试吗小哥说不清楚,可能有二面,也可能hr和你交流(感觉已经暗示我的死亡了)2.公司是干什么的小哥说他们是科技公司,他所在的部门是给证券,国债什么的设计软件的,所以也要用到springboot、redis、mq等然后我就再见挂电话了总结:小哥人非常好,我菜成这个样子也一直在引导我,但这问的有点少了吧(流汗),如果不算kpi,那可能就是一面不卡人吧
查看11道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务