zoukankan      html  css  js  c++  java
  • 2021“MINIEYE杯”中国大学生算法设计超级联赛(5)HDU7018 Banzhuan(阅读理解)

    Banzhuan

    *Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 102 Accepted Submission(s): 36
    *

    Problem Description

    Given a three-dimensional space of [1,n]×[1,n]×[1,n]. You're required to place some 1×1×1 cubes to make this 3D space look n×n square from above, from left and from front, while the plane xOy stand for the ground and z axis describes the height.

    But placing these cubes must follow some restrictions. Obviously, it must obey the gravity laws. It means, when beneath a cube is empty, the height of this cube will drop one, until its height is exactly 1 (touch the ground) or there is another cube below it.

    And besides that, placing cubes has some prices. If a cube is placed at an integer coordinate (x,y,z), the price will be x×y2×z.

    Now, satisfying all the requirements above, you're required to calculate the minimum costs and the maximum costs.

    Input

    The first line contains an integer T(T≤15). Then T test cases follow.

    For each test case, input a single integer n per line, while satisfying 1≤n≤1018.

    Output

    For each test case, output two lines. For the first line output the minimum costs mod 109+7. And for the second line, output the maximum costs mod 109+7.

    Sample Input

    1
    2
    

    Sample Output

    27
    60
    

    Source

    2021“MINIEYE杯”中国大学生算法设计超级联赛(5)

    题意极其坑逼...这个题实际上说你可以在一个(n imes n imes n)的空间放(1 imes 1 imes 1)的小立方体,放置的花费是(xy^2z),注意这个花费是放置位置处的花费,比如在(1, 1, 3)的位置放那么花费就是3,但是放完后这个小立方体会掉下去。问防止完后能使整个几何体的三视图都是(n imes n imes n)正方形的最大花费和最小花费。

    最大花费就是在z = n的这一层不断往下扔小立方体直到填满为止。最小花费为先填满最底层,然后在XOY平面的(2, 1), (3, 1)...(n, 1)以及(1, 2), (1, 3)...(1, n)这些位置不断往上放。最终的答案就是(max = n^2frac{n(n+1)}{2}frac{n(n+1)(2n+1)}{6}, min = frac{n^2(n+1)^2(2n+1))}{12}+frac{(n-1)^2(n+2)^2}{4}+(frac{n(n+1)(2n+1)}{6}-1)frac{(n+2)(n-1)}{2})

    注意涉及到除法,比赛的时候因为取模wa了无数次于是怒而写了发java的大数QwQ

    import java.math.BigInteger;
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int t = sc.nextInt();
            for(int i = 0; i < t; i++) {
                BigInteger n = sc.nextBigInteger();
                BigInteger nn = n.add(n);
                BigInteger mn = BigInteger.ZERO, mx = BigInteger.ZERO;
                BigInteger six = new BigInteger("6");
                BigInteger two = new BigInteger("2");
                BigInteger md = new BigInteger("1000000007");
                mx = n.pow(4);
                mx = mx.multiply(n.add(BigInteger.ONE));
                mx = mx.multiply(n.add(BigInteger.ONE));
                mx = mx.multiply(nn.add(BigInteger.ONE));
                mx = mx.divide(six);
                mx = mx.divide(two);
                mx = mx.mod(md);
                //System.out.println(mx);
    
    
                BigInteger p1 = BigInteger.ZERO, p2 = BigInteger.ZERO, p3 = BigInteger.ZERO;
                p1 = n.pow(2);
                p1 = p1.multiply(n.add(BigInteger.ONE));
                p1 = p1.multiply(n.add(BigInteger.ONE));
                p1 = p1.multiply(nn.add(BigInteger.ONE));
                p1 = p1.divide(six);
                p1 = p1.divide(two);
    
                p2 = n.add(two);
                p2 = p2.multiply(n.add(two));
                p2 = p2.multiply(n.subtract(BigInteger.ONE));
                p2 = p2.multiply(n.subtract(BigInteger.ONE));
                p2 = p2.divide(two);
                p2 = p2.divide(two);
    
                p3 = n.multiply(n.add(BigInteger.ONE));
                p3 = p3.multiply(nn.add(BigInteger.ONE));
                p3 = p3.divide(six);
                p3 = p3.subtract(BigInteger.ONE);
                p3 = p3.multiply(n.add(two));
                p3 = p3.multiply(n.subtract(BigInteger.ONE));
                p3 = p3.divide(two);
                mn = p1.add(p2.add(p3));
                mn = mn.mod(md);
                System.out.println(mn);
                System.out.println(mx);
            }
        }
    }
    
    
  • 相关阅读:
    关于 Mercury_Lc 说明
    Java 对象和类
    Java int 与 Integer 区别
    Java Number & Math 类
    HTML | CSS | JavaScript 常见错误
    B. Heaters ( Codeforces Round #515 (Div. 3) )
    A. Vova and Train ( Codeforces Round #515 (Div. 3) )
    数据结构实验之排序四:寻找大富翁(SDUT 3401)
    JavaScript 与 Java
    A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/15095873.html
Copyright © 2011-2022 走看看