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)
题意极其坑逼...这个题实际上说你可以在一个的空间放的小立方体,放置的花费是,注意这个花费是放置位置处的花费,比如在(1, 1, 3)的位置放那么花费就是3,但是放完后这个小立方体会掉下去。问防止完后能使整个几何体的三视图都是正方形的最大花费和最小花费。
最大花费就是在z = n的这一层不断往下扔小立方体直到填满为止。最小花费为先填满最底层,然后在XOY平面的(2, 1), (3, 1)...(n, 1)以及(1, 2), (1, 3)...(1, n)这些位置不断往上放。最终的答案就是
注意涉及到除法,比赛的时候因为取模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);
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2020-08-03 CH6803 导弹发射塔(二分图最大匹配/多重匹配)
2020-08-03 CH6802 車的放置(二分图最大匹配)