0%


情恨天
长剑耿介
长相思,在佳人。一日不见,思之如狂。狂兮狂兮可奈何?只恨相见.
既相见,何相识?芳草凋零,北雁南飞。飞兮飞兮留不住,自是流年。

作业调度方案

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

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

Read more »

能量项链

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
128
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,结果没用‘<=’反画蛇添足了……唉……太粗心了……

Read more »

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

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
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
program fruit;

var a:array [0..10001]of longint;

i,j,k,n:integer;

t,s:longint;

flag:boolean;

procedure fastsort(l,r:integer);

var lx,rx,pi:integer;

begin

lx:=l;rx:=r;pi:=a[l];

while lx<rx do begin

while a[rx]>pi do dec(rx);

if lx<rx then begin

t:=a[rx];a[rx]:=a[lx];a[lx]:=t;inc(lx);

end;

while a[lx]<pi do inc(lx);

if lx<rx then begin

t:=a[rx];a[rx]:=a[lx];a[lx]:=t;dec(rx);

end;

end;

if l<lx-1 then fastsort(l,lx-1);

if r>rx+1 then fastsort(rx+1,r);

end;

begin

assign(input,'fruit.in');reset(input);

assign(output,'fruit.ans');rewrite(output);

readln(n);

for i:=1 to n do read(a[i]);

fastsort(1,n);

s:=0;a[0]:=0;

for i:=1 to n do begin

s:=s+a[i]+a[i-1];a[i]:=a[i-1]+a[i];

for k:=i to n-1 do

if a[k]>a[k+1] then begin

t:=a[k];a[k]:=a[k+1];a[k+1]:=t;

end;

end;

dec(s,a[1]);

writeln(s);

close(input);close(output);

end.

其中还有许多可以优化的地方,如:可以用t:=a[i];a[i]:=a[n];a[n]:=t;来减少后面的排序次数,又数组已是有序的了故还可在冒泡排序上优化,可置一布尔型变量flag来提前结束排序.

但十个测试点都过了就不做了.