IT评测·应用市场-qidao123.com
标题:
牛客网BC115---超级圣诞树(java)
[打印本页]
作者:
八卦阵
时间:
2023-4-15 00:06
标题:
牛客网BC115---超级圣诞树(java)
和女朋友坐一块的时候,突然想到了,哈哈哈哈哈
不会很难!!!
[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; //
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4