牛客网BC115---超级圣诞树(java)

打印 上一主题 下一主题

主题 999|帖子 999|积分 2997

和女朋友坐一块的时候,突然想到了,哈哈哈哈哈
不会很难!!!
 
[code]import java.util.*;import java.lang.Math;// 注意类名必须为 Main, 不要有任何 package xxx 信息public class Main {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        /**                思考过程如下:        小三角形个数为 3^(n-1)        1 3 9 27        3^(1-1) = 1        3^(2-1) = 3        3^(3-1) = 9        3^(4-1) = 27        3^(5-1) = 81        // 去除杆子有多少层                                        用到了        n        3x1    3       3*2^(1-1)        3x2    6       3*2^(2-1)        3x4    12        3x8    24        3x16   48        int allP = 3 * (int)Math.pow(2, n - 1);                最底层三角形个数                        没用到        n        1   1   0+1             2^(n-1)        2   2   1+1                     3   4   2+1+1        4   8   4+2+1+1        5   16  8+4+2+1+1        6   32  16+8+4+2+1+1        int lastPT = Math.pow(2, n - 1)        最底层宽度  最底层三角形个数*6           用到了        n        1 6           2 12          3 24        4 48        5 96        int lastPW = (int)Math.pow(2, n - 1) * 6;        24 - 3 - 12 - 0        左边宽 最底层宽度 - 6 / 2  每三行-3   用到了        1 0        2 3-0        3 9-6-3-0        4 21-18-15-12-9-6-3-0        int leftW = (lastPW - 6) / 2;        最底层判断          需要        int nowP = 0;        int lastP = 3;        int checkN = 1;        if nowP = lastP            checkN++;            lastP += lastP        第几层,三角形大间隔    当checkN>2时,存在大间隔     最大间隔等于上一层最底层宽度-6                !!!!用到了!        int triW = 0;   // 初始值        if (nowP == lastP) {            checkN++;            lastP += lastP;            if (checkN > 2) {                triW = ((int)Math.pow(2, checkN - 2) - 1) * 6;          //
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

勿忘初心做自己

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表