4 条题解

  • 1
    @ 2022-10-28 22:13:50

    好久之前做的题了()刚刚看递交记录把题解翻了出来

    #include<bits/stdc++.h>
    using namespace std;
    int n,m,ai,Si,ans=1;
    int main(){
        cin>>n>>m;
        int face[n+1];
        string wok[n+1];
        for(int i=1;i<=n;i++){
            cin>>face[i]>>wok[i];
        }
        for(int i=1;i<=m;i++){
            cin>>ai>>Si;
            if(ai==face[ans]){
                ans-=Si;
            }else{
                ans+=Si;
            }
            if(ans<1){
                ans=ans+n;
            }
            if(ans>n){
                ans=ans-n;
            }
        }
        cout<<wok[ans];
        return 0;
    }
    
    • 0
      @ 2023-10-14 16:33:21
      1、定义两个数组,如p[100005], q[100005],分别用来存储朝向编号(0为朝里,1为朝外)和职业名称;
      
      2、输入数字n和m,以及两数组的各数值;
      
      3、开始寻找眼镜:
      
        (1)、从两数组的第一项出发;
      
        (2)、循环m次,每次输入两个数a和s,分别用来表示左/右指令和移动步数(0向左,1向右);
      
        (3)、在循环前可以先令sol = p[1], ans = q[1],h = 1;
      
        (4)、设循环到第i次时,p和q对应的序号为h,ans和sol的值也同时被更改为q[h]和p[h](此处用“if … else if … else …”句型):
      
             1’如果sol = 0,a = 0,那么p和q数组对应的序号h将-s,[if(h < 1), h = n];
      
             2’如果sol = 0, a = 1,那么p和q数组对应的序号h将+s, [if(h > n), h = 1];
      
             3’如果sol = 1, a = 0,那么p和q数组对应的序号h将+s, [if(h > n), h = 1];
      
             4’如果sol = 1, a = 1,那么p和q数组对应的序号h将-s, [if(h < n), h = n];
      
        (5)、循环结束后,最后输出q[h]的那一项职业名称即可。
      参考代码:
      #include <iostream>
      using namespace std;
      int p[100005], n, m, a, s;
      string q[100005];
      int main()
      {
          cin >> n >> m;
          for(int i = 1; i <= n; i++)
          {
              cin >> p[i] >> q[i];
          }
          int sol = p[1], h = 1;
          string ans = q[1];
          for(int i = 1; i <= m; i++)
          {
              cin >> a >> s;
              if((sol == 0 and a == 0) or (sol == 1 and a == 1))
              {
                  if(h - s < 1)
                  {
                      int b = h;
                      s -= b;
                      h = n - s;
                  }
                  else
                  {
                      h -= s;
                  }
                  sol = p[h], ans = q[h];
              }
              else if((sol == 0 and a == 1) or (sol == 1 and a == 0))
              {
                  if(h + s > n)
                  {
                      int b = n - h;
                      h = s - b;
                  }
                  else
                  {
                      h += s;
                  }
                  sol = p[h], ans = q[h];
              }
          }
          cout << ans;
          return 0;
      }
      
      • -2
        @ 2022-7-14 16:40:41
        请问谁能发个题解吗?
        
      • -3
        @ 2022-9-10 13:38:41

        #include <iostream> using namespace std; int a[100002]; string b[10002]; int main() { int n,m,x,y; cin >> n >> m; for (int i = 0; i <= n; i++) { cin >> a[i] >> b[i]; } int s = 1; for (int i = 0; i <= m; i++) { cin >> x >> y; if (a[s] == 0) { if (x == 0) { s = s - y; } else { s = s + y; } } else { if (x == 0) { s = s + y; } else { s = s - y; } } if (s > n) { s = s - n; } if (s <= 0) { s = s + n; } } cout << b[s]; return 0; }

        • 1

        信息

        ID
        1396
        时间
        1000ms
        内存
        256MiB
        难度
        6
        标签
        递交数
        220
        已通过
        67
        上传者