• 洛谷 P1076 寻宝 题解


    今天又TM考试了......

    这是T1,然后我模拟20分滚粗。

    Analysis

    在每层的时候用编号%这层可以上楼的房间个数就行了。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #define mod 20123
     6 #define maxn 10010
     7 #define maxm 110
     8 using namespace std;
     9 inline int read()
    10 {
    11     int x=0;
    12     bool f=1;
    13     char c=getchar();
    14     for(; !isdigit(c); c=getchar()) if(c=='-') f=0;
    15     for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+c-'0';
    16     if(f) return x;
    17     return 0-x;
    18 }
    19 inline void write(int x)
    20 {
    21     if(x<0){putchar('-');x=-x;}
    22     if(x>9)write(x/10);
    23     putchar(x%10+'0');
    24 }
    25 int n,m,st,ans;
    26 int map[maxn][maxm],map_s[maxn][maxm],num[maxn];
    27 int main()
    28 {
    29 //    freopen("treasure.in","r",stdin);
    30 //    freopen("treasure.out","w",stdout);
    31     n=read();m=read();
    32     int cnt=0,c=1;
    33     for(int i=1;i<=n*m;i++)
    34     {
    35         int x,y;
    36         
    37         x=read();y=read();
    38         map_s[c][cnt]=x;
    39         if(x==1)num[c]++;
    40         map[c][cnt]=y;
    41         if(cnt==m-1)
    42         {
    43             cnt=0;
    44             c++;
    45         }
    46         else cnt++;
    47     }
    48     st=read();
    49     for(int i=1;i<=n;i++)
    50     {
    51         if(map_s[i][st]==0)
    52         {
    53             int xb=map[i][st];
    54             xb%=num[i];
    55             if(xb==0)xb+=num[i];
    56             ans+=map[i][st];
    57             ans%=mod;
    58             while(xb>0)
    59             {
    60                 if(st==m-1)st=0;
    61                 else st++;
    62                 if(map_s[i][st]==1)xb--;
    63             }
    64         }
    65         else if(map_s[i][st]==1)
    66         {
    67             int xb=map[i][st]-1;
    68             xb%=num[i];
    69             if(xb==0)xb+=num[i];
    70             ans+=map[i][st];
    71             ans%=mod; 
    72             while(xb>0)
    73             {
    74                 if(st==m-1)st=0;
    75                 else st++;
    76                 if(map_s[i][st]==1)xb--;
    77             }
    78         }
    79     }
    80     write(ans);
    81     return 0;
    82 }
    请各位大佬斧正(反正我不认识斧正是什么意思)
  • 相关阅读:
    区块链|学习笔记(三)
    左神算法之获取栈中最小值
    23种设计模式之适配器模式
    二叉树序列化和反序列化
    归并排序
    通过集合构建RDD或者DataFrame
    内核源码分析——shuffle
    问题
    函数参数
    问题记录
  • 原文地址:https://www.cnblogs.com/handsome-zyc/p/11288073.html
Copyright © 2020-2023  润新知