1 条题解

  • 0
    @ 2021-6-15 1:39:11

    C++ :

    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <iterator>
    using namespace std;
    
    const int N = 27;
    int a[N * N], Machine[N][N], Time[N][N], Cur[N], Last[N];
    struct Range
    {
    	int Begin, Last;
    	Range() {Begin = Last = 0;}
    	Range(int a, int b) {Begin = a; Last = b;}
    	friend bool operator < (const Range& a, const Range& b) {return a.Begin < b.Begin;}
    } c;
    set<Range> s[N];
    set<Range>::iterator I;
    
    int main()
    {
    	int m, n, i, j, Res = 0;
    	
    	cin >> m >> n;
    	for (i = 0; i < m * n; ++i) cin >> a[i];
    	for (i = 1; i <= n; ++i)
    		for (j = 1; j <= m; ++j) cin >> Machine[i][j];
    	for (i = 1; i <= n; ++i)
    		for (j = 1; j <= m; ++j) cin >> Time[i][j];
    	
    	for (i = 1; i <= m; ++i) s[i].insert(Range(0, N * N));
    	for (i = 0; i < m * n; ++i)
    	{
    		const int& k = a[i];
    		const int& b = Machine[k][++Cur[k]];
    		int& l = Last[k];
    		const int& t = Time[k][Cur[k]];
    		for (I = s[b].begin(); I != s[b].end(); ++I)
    			if (I -> Begin >= l && I -> Last >= t)
    			{
    				c = *I; s[b].erase(I);
    				l = (c.Begin += t); c.Last -= t;
    				if (c.Last) s[b].insert(c);
    				break;
    			}
    			else if (I -> Begin < l && I -> Begin + I -> Last >= t + l)
    			{
    				c = *I; s[b].erase(I);
    				s[b].insert(Range(c.Begin, l - c.Begin));
    				c.Last -= l - c.Begin + t;
    				c.Begin = (l += t);
    				s[b].insert(c);
    				break;
    			}
    	}
    	
    	for (i = 1; i <= m; ++i) Res = max(Res, s[i].rbegin() -> Begin);
    	cout << Res << endl;
    	
    	return 0;
    } 
    
    

    Pascal :

    var
     m,n,i,j,k,x,max:longint;
     a:array[1..1000] of longint;
     machine:array[1..100,0..400] of longint;
     p,t:array[1..100] of longint;
     f:array[1..100,1..100,1..2] of longint;
     flag:boolean;
     begin
     readln(m,n);
     fillchar(a,sizeof(a),0);
     fillchar(machine,sizeof(machine),0);
     fillchar(p,sizeof(p),0);
     fillchar(t,sizeof(t),0);
     fillchar(f,sizeof(f),0);
     for i:=1 to m*n do read(a[i]);
     for i:=1 to n do
       for j:=1 to m do
        read(f[i,j,1]);
     for i:=1 to n do
       for j:=1 to m do
        read(f[i,j,2]);
     for i:=1 to m*n do
     begin
       inc(p[a[i]]);
       x:=f[a[i],p[a[i]],1];
       for j:=t[a[i]]+1 to machine[x,0]+1 do
       begin
        flag:=true;
        for k:=1 to f[a[i],p[a[i]],2] do
         if machine[x,j+k-1]=1 then
         begin
          flag:=false;
          break;
         end;
        if flag then break;
       end;
       for k:=j to j+f[a[i],p[a[i]],2]-1 do machine[x,k]:=1;
       if k>machine[x,0] then machine[x,0]:=k;
       t[a[i]]:=k;
     end;
     max:=-maxlongint;
     for i:=1 to m do if machine[i,0]>max then max:=machine[i,0];
     writeln(max);
     end.
    
    • 1

    信息

    ID
    251
    时间
    1000ms
    内存
    125MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者