2012年分区联赛普级组第二题 寻宝

本文解析了2012年分区联赛普及组第二题“寻宝”的解题思路。通过使用三个数组分别存储房间数字、是否可通往上层以及可通往上层数量,并利用循环模拟来解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2012年分区联赛普级组第二题 <wbr>寻宝
2012年分区联赛普级组第二题 <wbr>寻宝
2012年分区联赛普级组第二题 <wbr>寻宝


解题思路: 先读入数据,用三个数组分别储存每间房牌子上的数字、每间房可不可以通往上层和每层楼有多少个可以通往上层的房,然后用循环模拟,先加上该房间里牌子上的数,然后用 repeat 模拟在该层楼转圈。最后输出 ans mod 20123 的值即可。


程序:
const
  maxn=10000;
  maxm=100;
var
  a:array[1..maxn,0..maxm]of longint;
  f:array[1..maxn,0..maxm]of boolean;
  d:array[1..maxn] of longint;
  n,m,start:longint;
  ans:int64;

procedure init;
  var
    i,j,x:longint;
  begin
    //assign(input,'treasure,in');reset(input);
    // assign(output,'treasure.out');rewrite(output);
    readln(n,m);
    fillchar(a,sizeof(a),0);
    fillchar(f,sizeof(f),false);
    for i:=1 to n do
      for j:=1 to m do
        begin
          readln(x,a[i,j-1]);
          if x=1 then begin f[i,j-1]:=true; inc(d[i]); end;
        end;
    readln(start);
    //close(input);
end;

procedure main;
  var
    i,j,nown,nowm,t,x:longint;
  begin
    nown:=1;
    nowm:=start;
    t:=0;
    for i:=1 to n do
      begin
        ans:=ans+a[nown,nowm];
        x:=(a[nown,nowm]-1) mod d[i]+1;
        repeat
          if (f[nown,nowm]=false) then inc(nowm);
          if f[nown,nowm] then begin inc(t); if t=x then break; inc(nowm); end;
          if nowm=m then nowm:=0;
        until t=x;
        t:=0;
        inc(nown);
      end;
    ans:=ans mod 20123;
    writeln(ans);
    //close(output);
end;

begin
  init;
  main;
end.


版权属于: Chris
转载时必须以链接形式注明原始出处及本声明。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值