为啥报错啊

Mapleleave  •  3年前


本地能跑

#include<algorithm>
#include<string.h>
#include<iostream>

int b[100];//第一台机器处理的时间
int c[100];//第二胎机器处理的时间
int f[100][100];
/*
    f[i][j]表示前i个作业A机器用了j时间的条件下B最少花费的时间 
*/
int time[100];//时间
int a;

int min(int x, int y) {
    return x < y ? x : y;
}

int max(int x, int y) {
    return x > y ? x : y;
}

int schedule() {
    int sumA = b[1];
    //k = 1
    for (int x = 0; x < b[1]; x++) {
        f[1][x] = b[1];
    }
    f[1][b[1]] = min(c[1], b[1]);
    //初始化
    for (int i = 2; i <= a; i++) {
        for (int j = 0; j <= a; j++) {
            f[i][j] = INT_MAX;
        }
    }
    //k >= 2
    for (int k = 2; k <= a; k++) {
        sumA += b[k];
        time[k] = INT_MAX;
        for (int x = 0; x <= sumA; x++) {
            if (x < b[k]) {
                f[k][x] = f[k - 1][x] + b[k];
            }
            else {
                f[k][x] = min(f[k - 1][x] + b[k], f[k - 1][x - b[k]]);
            }
            time[k] = min(time[k], max(x, f[k][x]));
        }
    }
    return time[a];
}

int main() 
{
	/*printf("输入数量:");*/
	scanf("%d", &a);
	/*printf("输入作业1:");*/
	for (int i = 1; i <= a; i++)
	{
		scanf("%d", &b[i]);
	}
	/*printf("输入作业2:");*/
	for (int i = 1; i <= a; i++)
	{
		scanf("%d", &c[i]);
	}
    printf("%d\n", schedule());
    /*
	for (int i = 1; i <= a; i++)
	{
		printf("%d\n",b[i]);
	}
	for (int i = 1; i <= a; i++)
	{
		printf("%d\n", c[i]);
	}*/
    return 0;
}

评论:

函数min、max换个名字,比如mymin、mymax。变量time也换个名字,比如mytime。


刷完前300题=入门级省一  •  3年前

把INT_MAX换成int最大值

测评信息: Main.cc: In function ‘int schedule()’: Main.cc:32:23: error: ‘INT_MAX’ was not declared in this scope f[i][j] = INT_MAX; ^~~ Main.cc:32:23: note: ‘INT_MAX’ is defined in header ‘’; did you forget to ‘#include ’? Main.cc:4:1: +#include

Main.cc:32:23: f[i][j] = INT_MAX; ^~~ Main.cc:38:21: error: ‘INT_MAX’ was not declared in this scope mytime[k] = INT_MAX; ^~~ Main.cc:38:21: note: ‘INT_MAX’ is defined in header ‘’; did you forget to ‘#include ’?

虚拟环境里面好像也不支持


Mapleleave  •  3年前

没有INT_MAX这个东西,你要手动赋一个很大的值。


刷完前300题=入门级省一  •  3年前

请先登录,才能进行评论