A. 空间 67108864
256MB = 256 * 1024 KB = 256 * 1024 * 1024 B = 256 * 1024 1024 * 8位
所以答案为256 * 1024 1024 * 8 / 32 = 67108864
B. 卡片 3181
import java.util.Arrays;
public class Main {
static int[] num = new int[11];
public static void main(String[] args) {
Arrays.fill(num, 2021);
boolean flag = false;
for (int i = 1; i < 10000; i++) {
int t = i;
while(t>0)
{
num[t%10] -- ;
if(num[t%10] == 0)
{
flag = true;
break;
}
t/=10;
}
if(flag)
{
System.out.println(i);
break;
}
}
}
}
C. 直线 40257
class Line
{
double k,b;
Line(double k, double b) {
this.k = k;
this.b = b;
}
}
public class Main {
static int N = 200000; //一共400多个点,比400^2大就行
static int n;
static Line[] l = new Line[N];
public static void main(String[] args) {
for (int x1 = 0; x1 < 20; x1++)
for (int y1 = 0; y1 < 21; y1++)
for (int x2 = 0; x2 < 20; x2++)
for (int y2 = 0; y2 < 21; y2++)
if(x1!=x2)
{
double k = (double)(y2 - y1)/(x2 - x1);
double b = y1 - k * x1;
boolean flag = true;
for(int i = 0;i < n;i++)
{
//double不能直接用 == 比大小
//https://blog.csdn.net/Venhoul/article/details/123018594
if(Math.abs(l[i].k - k) < 1e-8 && Math.abs(l[i].b - b) < 1e-8)
{
flag = false;
break;
}
}
if(flag) l[n++] = new Line(k,b);
}
System.out.println(n + 20); //加的是竖线(斜率不存在)
}
}
D. 货物摆放 2430
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
long n = Long.parseLong(input[0]);
ArrayList<Long> d = new ArrayList<>();
for (long i = 1; i * i <= n; i ++ )
if (n % i == 0) //必须除得尽(三个数都是n的约数)
{
d.add(i);
if (n / i != i) d.add(n / i);
}
int res = 0;
for (Long a: d)
for (Long b: d)
for (Long c: d)
if (a * b * c == n)
res ++ ;
System.out.println(res);
}
}
E. 路径 10266837
spfa算法 https://www.acwing.com/activity/content/code/content/2367909/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
public class Main {
static int N = 2200, M = N * 50; //2021个点,每个点最多连43条边。
static int n, idx;
static int[] h = new int[N], e = new int[M], w = new int[M], ne = new int[M];
static int[] q = new int[N], dist = new int[N];
static boolean[] st = new boolean[N];
static int gcd(int a, int b) // 欧几里得算法
{
return b!=0 ? gcd(b, a % b) : a;
}
static void add(int a, int b, int c) // 添加一条边a->b,边权为c
{
e[idx] = b; w[idx] = c; ne[idx] = h[a]; h[a] = idx ++ ;
}
private static int spfa() // 求1号点到n号点的最短路距离
{
Arrays.fill(dist,0x3f3f3f3f); //初始化所有点的距离为最大值,不能写成0x3f
dist[1] = 0; //1号点距离为0
Queue<String> q=new LinkedList<>();
q.offer(1+""); //把1号点放入队列。队列元素必须是String,所以还得转换
st[1] = true; //存储当前点是否在队列当中。防止队列当中存储重复点。
while (q.size()>0) //当队列不空
{
int t = Integer.parseInt(q.poll()); //去除队头
st[t] = false; //点从队列中出来了,就置为false
for (int i = h[t]; i != -1; i = ne[i]) //更新t的所有邻边
{
int j = e[i];
if (dist[j] > dist[t] + w[i]) //看看是否需要更新
{
dist[j] = dist[t] + w[i];
if (!st[j]) // j不在队列中,才把j插入进去。防止重复插入
{
q.offer(j+"");
st[j] = true;
}
}
}
}
return dist[n];
}
public static void main(String[] args) {
n = 2021;
Arrays.fill(h, -1);
for (int i = 1; i <= n; i ++ )
for (int j = Math.max(1, i - 21); j <= Math.min(n, i + 21); j ++ )
{
int d = gcd(i, j);
add(i, j, i * j / d); //最小公倍数
}
spfa();
System.out.println(dist[n]); //到第n个点的距离
}
}