作业调度方案

本来想用记录p=record u,b,e:integer; end; (u为第几道工序,b为开始时间,e为结束时间)

来实现的,直接排还是挺方便的,但有些地方不好实现就没做下去……
直接排:

1
2
3
4
5
6
7
8
9
10
11
for I:=1 to m*n do begin
j:=1;
while p[I,j].e<>0 do inc(j);{p[I,j].e=0意味着p[I,j]已被安排过了,下一道工序}
p[I,j].b:=p[I-1,j].e;{在同一个机器上的上一道工序结束时间}
p[I,j].e:=p[I,j].b+t[I,j];{t[I,j]为该道工序所占时间}
end;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
program jsp;
const nn=20;
var f:array[1..nn,0..nn*nn]of boolean;//each machine condition;
t:array[1..nn,1..nn]of integer;//cover time;
e:array[1..nn,0..nn]of integer;//end time;
a:array[1..nn*nn]of integer;//following;
b:array[1..nn,1..nn]of integer;//belong to machine
g:array[1..nn*nn]of integer;//dealing with;
flag:boolean;
i,j,m,n,k,best,nt,nm:integer;
begin
assign(input,&#39;jsp.in&#39;);reset(input);
assign(output,&#39;&#39;);rewrite(output);
readln(m,n);
fillchar(a,sizeof(a),0);
fillchar(e,sizeof(e),0);
fillchar(f,sizeof(f),true);
fillchar(g,sizeof(g),0);
for i:=1 to m*n do read(a[i]);readln;
for i:=1 to n do begin
for j:=1 to m do
read(b[i,j]);
end;
for i:=1 to n do begin
for j:=1 to m do
read(t[i,j]);
readln;
end;
for i:=1 to m*n do begin
inc(g[a[i]]);
nt:=t[a[i],g[a[i]]];
nm:=b[a[i],g[a[i]]];{nt:needtime;nm:machine}
for j:=e[a[i],g[a[i]]-1]to 400 do begin{从该工件的上一个工序结束时间开始搜索}
flag:=true;
for k:=j to j+nt do
if k&amp;lt;=400 then
flag:=flag and f[nm,k];
if flag then begin{如果搜索成功}
e[a[i],g[a[i]]]:=j+nt;{记下结束时间}
for k:=j+1 to j+nt-1 do f[nm,k]:=false;
break;{减少搜索}
end;
end;
end;
best:=0;
for i:=1 to n do {从每道工序入手,但如果从每个机器入手呢?}
if best&amp;lt;e[i,m]then best:=e[i,m];
writeln(best);
close(input);close(output);
end.

欢迎关注我的公众号『日技』

评论和共享

noip 2006 能量项链 energy

发布在 Pascal

能量项链

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
rogram energy;
{20:02 }
var
a1,a2:array[1..200]of integer;
q:array[1..200,1..200]of longint;
i,j,n,k,m,p:integer;
best:longint;
begin
assign(input,'energy.in');reset(input);
assign(output,'energy.ans');rewrite(output);
readln(n);
for i:=1 to n do read(a1[i]);
readln;
for i:=1 to n-1 do a2[i]:=a1[i+1];
a2[n]:=a1[1];
m:=n*2-1;
for i:=n+1 to m do begin
a1[i]:=a1[i-n];a2[i]:=a2[i-n]
end;
//for i:=1 to m do writeln(a1[i],' ',a2[i],' ');
fillchar(q,sizeof(q),0);
for p:=1 to n-1 do
for i:=1 to m-1 do
begin
j:=i+p;
if j>m then break;
for k:=i to j-1 do begin
if q[i,j]<q[i,k]+q[k+1,j]+a1[i]*a2[k]*a2[j]
then q[i,j]:=q[i,k]+q[k+1,j]+a1[i]*a2[k]*a2[j];
end;
end;
best:=0;
for i:=1 to n do
if best<q[i,i+n-1]then best:=q[i,i+n-1];
writeln(best);
close(input);close(output);
end.

欢迎关注我的公众号『日技』

评论和共享

金明的预算方案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
program budget;
 
{20:03 }
 
type node=record
 
            u:integer;
 
       v,p:array[0..2]of integer;
 
     end;
 
var w:array[1..60]of node;
 
    f:array[0..60,0..2000]of longint;
 
    vx,px,qx,g:array[1..60]of integer;
 
    m,n,i,k,j:integer;
 
begin
 
assign(input,'budget.in');reset(input);
 
assign(output,'budget.out');rewrite(output);
 
readln(n,m);
 
k:=0;
 
for i:=1 to m do begin
 
      readln(px[i],vx[i],qx[i]);
 
      if qx[i]=0 then begin
 
                   inc(k);g[i]:=k;
 
                   with w[k] do begin
 
                   u:=0;
 
                   v[0]:=vx[i];p[0]:=px[i];
 
                   for j:=1 to 2 do begin
 
                            v[j]:=0;p[j]:=0;
 
                   end;
 
                   end;
 
         end;
 
    end;
 
for i:=1 to m do begin
 
         if qx[i]<>0 then
 
         with w[g[qx[i]]] do begin
 
                   inc(u);v[u]:=vx[i];p[u]:=px[i];
 
         end;
 
end;
 
for i:=1 to k do
 
         with w[i] do begin
 
                   write('w[',i,']:');
 
         for j:=0 to 2 do write('(',v[j],',',p[j],') ');
 
                   writeln;
 
end;
 
         
 
fillchar(f,sizeof(f),0);
 
         
 
for i:=1 to k do
 
         for j:=1 to n do
 
                   with w[i] do begin
 
             f[i,j]:=f[i-1,j];
 
                   
 
             if (f[i,j]< (f[i-1,j-p[0]]+p[0]*v[0]))and(j>=p[0]) then
 
                            f[i,j]:=f[i-1,j-p[0]]+p[0]*v[0];
 
                   
 
                   if (f[i,j]< (f[i-1,j-p[0]-p[1]]+p[0]*v[0]+v[1]*p[1]))and(j>=p[0]+p[1]) then
 
                            f[i,j]:=f[i-1,j-p[0]-p[1]]+p[0]*v[0]+v[1]*p[1];
 
                   
 
                   if (f[i,j]< (f[i-1,j-p[0]-p[2]]+p[0]*v[0]+p[2]*v[2]))and(j>=p[0]+p[2]) then
 
                            f[i,j]:=f[i-1,j-p[0]-p[2]]+p[0]*v[0]+p[2]*v[2];
 
                   
 
                   if (f[i,j]< (f[i-1,j-p[0]-p[1]-p[2]]+p[0]*v[0]+v[1]*p[1]+p[2]*v[2]))and(j>=p[0]+p[1]+p[2]) then
 
                            f[i,j]:=f[i-1,j-p[0]-p[1]-p[2]]+p[0]*v[0]+v[1]*p[1]+p[2]*v[2];
 
                   writeln('f[',i,',',j,']:',f[i,j]);
 
         end;
 
         writeln(f[k,n]);
 
         close(input);close(output);
 
end.

欢迎关注我的公众号『日技』

评论和共享

就像解题报告中说的超简单,但还是出了许多小毛病,如刚开始将sum同avi,paper等定义在一起,而我为了省空间将它们限制在0..100,故算出来的sum错误无疑了;用字符读入数据时忘了空格……最后在比较时本想输出sum同最先出现的人却费事的用downto,结果没用‘<=’反画蛇添足了……唉……太粗心了……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
program scholar;
type node=record
name:string[20];
avi,ping,paper:0..100;
bu,west:boolean;
sum:integer;
end;
var stu:array [0..100] of node;
i,n,max:integer;
sumup:longint;
c:char;
begin
assign(input,'scholar1.in');reset(input);
assign(output,'');rewrite(output);
readln(n);
for i:=0 to 100 do
with stu[i] do begin
name:='';
avi:=0;ping:=0;paper:=0;sum:=0;
bu:=false;west:=false;
end;
for i:=1 to n do
with stu[i] do begin
read(c);
while c<>' ' do begin name:=name+c;read(c);end;
read(avi);read(ping);
read(c);
read(c);if c='Y'then bu:=true else bu:=false;
read(c);
read(c);if c='Y'then west:=true else west:=false;
readln(paper);
if (avi>80)and(paper>0)then inc(sum,8000);
if (avi>85)and(ping>80) then inc(sum,4000);
if avi>90 then inc(sum,2000);
if (avi>85)and west then inc(sum,1000);
if (ping>80)and bu then inc(sum,850);
end;
sumup:=0;max:=0;
for i:=1 to n do begin
sumup:=sumup+stu[i].sum;
if max<stu[i].sum then begin
max:=stu[i].sum;stu[0]:=stu[i];
end;
end;
writeln(stu[0].name);writeln(stu[0].sum);writeln(sumup);
close(input);close(output);
end.

欢迎关注我的公众号『日技』

评论和共享

NOIP 2004 津津的储蓄计划

发布在 Pascal

可以说超简单的一道题,学过数组的人都应会做

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
program save;
var a:array[0..12]of integer;
i,x,p:integer;
begin
assign(input,'save.in');reset(input);
assign(output,'');rewrite(output);
for i:=1 to 12 do a[i]:=300;
a[0]:=0;p:=0;
for i:=1 to 12 do begin
readln(x);inc(a[i],a[i-1]);dec(a[i],x);
if a[i]<0 then begin
writeln('-',i);
close(input);close(output);exit;
end else {if a[i]>=100 then} begin
p:=(a[i]div 100)*100;
inc(a[0],p);
a[i]:=a[i]-p;
end;
end;
a[0]:=a[0]*6 div 5;
writeln(a[0]+a[12]);
close(input);close(output);
end.

欢迎关注我的公众号『日技』

评论和共享

  • 第 1 页 共 1 页
作者的图片

Jiezhi

一个小码农,辛勤地走在通往大牛的路上。


安卓开发


Nanjing China