CSP-J2 2019解题报告

前言

今年的题目明显比较刺激,但是我的热情没有变,AFOK快乐

题目

如下

T1 数字游戏

  • 数字游戏

小 K 同学向小 P 同学发送了一个长度为 8 的 01 字符串来玩数字游戏,小 P 同学想要知道字符串中究竟有多少个 1。
注意:01 字符串为每一个字符是 0 或者 1 的字符串,如“101”(不含双引号)为一个长度为 3 的 01 字符串。

签到题
会输入就能A(逃
AC代码:

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 纪念品

  • 纪念品

    完全背包
    貌似还是原题。我知道的太多了
    Q w Q QwQ
    代码:
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 加工零件

  • 加工零件

    分奇偶数路径乱搞一通 B F S BFS 即可
    唯一需要注意de是要用邻接表存储输入数据
    AC代码:
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

发布了23 篇原创文章 · 获赞 37 · 访问量 9050

猜你喜欢

转载自blog.csdn.net/weixin_41221124/article/details/103214848