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\times n \times n\)的空間放\(1\times 1\times 1\)的小立方體,放置的花費是\(xy^2z\),注意這個花費是放置位置處的花費,比如在(1, 1, 3)的位置放那么花費就是3,但是放完后這個小立方體會掉下去。問防止完后能使整個幾何體的三視圖都是\(n\times n \times n\)正方形的最大花費和最小花費。

最大花費就是在z = n的這一層不斷往下扔小立方體直到填滿為止。最小花費為先填滿最底層,然后在XOY平面的(2, 1), (3, 1)...(n, 1)以及(1, 2), (1, 3)...(1, n)這些位置不斷往上放。最終的答案就是\(max = n^2\frac{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);
        }
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM