CSP-J2 2019
前言
今年的题目明显比较____,AK快乐
题目
T1 数字游戏
小 K 同学向小 P 同学发送了一个长度为 8 的 01 字符串来玩数字游戏,小 P 同学想要知道字符串中究竟有多少个 1。
注意:01 字符串为每一个字符是 0 或者 1 的字符串,如“101”(不含双引号)为一个长度为 3 的 01 字符串。
签到题
Var s:char;
tot,i:word;
Begin
for i:=1 to 8 do Begin
read(s);
if s='1' then tot:=tot+1;
end;
write(tot);
end.
T2 公交换乘

按照题目描述模拟
Var n,tool,price,time,pos,tag,count,i,j,page:longint;
member:array[1..100005] of record
price,time:longint;
flag:boolean;
end;
Begin
readln(n);
count:=0;
tag:=1;
for i:=1 to n do
Begin
read(tool,price,time);
if tool = 0 then
Begin
pos:=pos+1;
member[pos].price:=price;
member[pos].time:=time;
for j:=tag to pos do
Begin
if member[pos].time-member[j].time > 45 then
Begin
tag:=j+1;
break;
end;
end;
count:=count+price;
end
else
Begin
page:=0;
for j:=tag to pos do
Begin
if not member[j].flag then
Begin
if time-member[j].time <= 45 then
Begin
if member[j].price >= price then
Begin
member[j].flag:=true;
page:=1;
break;
end;
end;
end;
end;
if page = 0 then
Begin
count:=count+price;
end;
end;
end;
write(count);
end.
T3 纪念品

完全背包裸题
状态转移:
代码:
uses math;
Var t,n,m,i,j,k:longint;
p:array[1..105,1..105] of longint;
f:array[0..10005] of longint;
Begin
read(t,n,m);
for i:=1 to t do
Begin
for j:=1 to n do
Begin
read(p[i][j]);
end;
end;
for i:=1 to t-1 do
Begin
fillchar(f,sizeof(f),0);
for j:=1 to n do
Begin
for k:=p[i][j] to m do
Begin
f[k]:=max(f[k],f[k-p[i][j]]-p[i][j]+p[i+1][j]);
end;
end;
m:=m+f[m];
end;
write(m);
end.
T4 加工零件

分奇偶数路径跑 即可,当然也可以用最短路做。
观察数据大小,显然不能用邻接矩阵。由于不需要记录边权,所以可以通过记录 对于一个点 u 的所有与之相连的点 v(即记录点的关系) 存储边的信息。当然也可以用前向星 ,然而前向星不是一般的烦T^T。
Var que:array[0..1000005,1..2] of longint;
flag:array[0..100005,1..2] of longint;
add:array[0..100005] of longint;
store:array[0..100005,0..105] of longint;
n,m,q,head,tail,i,u,v,p1,p2:longint;
Begin
readln(n,m,q);
for i:=1 to m do
Begin
readln(u,v);
inc(add[u]);
store[u,add[u]]:=v;
inc(add[v]);
store[v,add[v]]:=u;
end;
for i:=1 to n do
Begin
flag[i,1]:=maxlongint;
flag[i,2]:=maxlongint;
end;
que[1,1]:=1;
que[1,2]:=0;
head:=0;
tail:=1;
while head<tail do
Begin
inc(head);
for i:=1 to add[que[head,1]] do
Begin
if ((que[head,2]+1)mod 2=1) and (flag[store[que[head,1],i],1]>que[head,2]+1) then
Begin
inc(tail);
que[tail,1]:=store[que[head,1],i];
que[tail,2]:=que[head,2]+1;
flag[store[que[head,1],i],1]:=que[head,2]+1;
end;
if ((que[head,2]+1)mod 2=0) and (flag[store[que[head,1],i],2]>que[head,2]+1) then
Begin
inc(tail);
que[tail,1]:=store[que[head,1],i];
que[tail,2]:=que[head,2]+1;
flag[store[que[head,1],i],2]:=que[head,2]+1;
end;
end;
end;
for i:=1 to q do
Begin
readln(p1,p2);
if add[1]=0 then
Begin
writeln('No');
continue;
end;
if p2 mod 2=0 then
Begin
if p2>=flag[p1,2] then
Begin
writeln('Yes');
end
else
Begin
writeln('No');
end;
end
else
Begin
if p2>=flag[p1,1] then
Begin
writeln('Yes');
end
else
Begin
writeln('No');
end;
end;
end;
end.
寄语
这套题目整体难度实际上是偏低的
我自闭了却是没跑的既定事实(雾)
Good luck & Have fun

浙公网安备 33010602011771号