题解

34 条题解

  • 20
    @ 2017-05-23 18:10:46
    #include<cstdio>
    #define              A int
    #define            B       n
    #define          C           m
    #define        E               ,                               
    #define      F                 now
    #define    D                    step               
    #define          G          =               
    #define          H  direction              
    #define                                        I p
    #define                                      J    char  
    #define                                    K         name              
    #define                                  L             ;
    #define                                M                scanf                                             
    #define                              N                    " %d%d"
    #define                            O                        "%d%s"                         
    #define                          P                             (                                         
    #define                        Q                                  )                                            
    #define                      R                                       &                        
    #define                        S                                  for                
    #define                          T                               <                                 
    #define                            U                           +            
    #define                              V                       -                               
    #define                                W                   0
    #define                                  X               i            
    #define                                    Y          if                      
    #define                                      Z      %
    #define                                QAQ                {
    #define                                QWQ                }
    #define                                QVQ                [
    #define                                QMQ                ] 
    #define                                                                     EX "%s"           
    #define                                                                   AA      11                                  
    #define                                                                 BB          100005                                  
    #define                                                               CC             else                                  
    #define                                                             DD                  main
    #define                                                           EE                     using
    #define                                                         FF                         std     
    #define                                                           GG                namespace
    #define                                                               HH              m--
    #define                                                                  II        ++i
    #define                                                                  JJ       while
    #define                                                                  KK       printf
    #define                                                                  LL       return
    
    
        EE GG FF 
             L A DD P 
                Q QAQ
                       A B E C E D E F         G W E H QVQ         BB QMQ             E I L
                J K QVQ      BB QMQ QVQ AA             /*"QAQ"*/                          QMQ L
               M P N E R B E                                                             R C Q L
                S P A X G W L X               T B L                                        II Q
                 M P O E R H QVQ       X QMQ E K QVQ  X QMQ Q L JJ P HH Q QAQ   M P N E R I E R
                 D Q L Y P H QVQ  F QMQ Q Y P I Q F G P F V D U  B Q Z B L CC F G P F
               U D Q Z B L CC Y P I
           Q F G P F U D Q Z B L
        CC F G P F V D U B Q 
      Z B L QWQ  KK P EX E 
    K QVQ F QMQ Q L LL W L QWQ
    

    完美AC/

  • 1
    @ 2019-03-15 20:13:40

    nb

  • 1
    @ 2018-03-15 17:52:07

    关键都在一句话里了.对于某个询问来讲,它模拟的方向和左右的方向以及小人脸部的朝向有关系.可以用异或运算判断模拟的方向,如果异或结果是1就逆时针,否则顺时针.

    #include<bits/stdc++.h>
    using namespace std;
    int n,m,k,a[123456];
    string s[202020];
    int main()
    {
    int i;
    scanf("%d%d",&n,&m);
    for (i=0;i<n;++i) cin>>a[i]>>s[i];
    for (;m--;) 
      {
      int b,y;
      scanf("%d%d",&b,&y);
      k=(k+y*(b^a[k]?1:-1)+n)%n;//关键都在这句话里了.
      }
    cout<<s[k];
    }
    
  • 0
    @ 2020-04-08 14:57:07
    #include <iostream>     //[2016提高组Day1-A]玩具谜题
    #include <algorithm>
    using namespace std;
    
    int main()
    {
        int n, m;
        cin >> n >> m;
        int ans = 0;
        int *f = new int[n];
        string *name = new string[n];
        for (int i = 0; i < n; i++)
            cin >> f[i] >> name[i];
        int a, s, k = 0;
        for (int i = 0; i < m; i++)
        {
            cin >> a >> s;
            if(a == 1)
                if (f[ans] == 0)
                    ans = (ans + s) % n;
                else
                    ans = (ans + n - s) % n;
            else
                if(f[ans] == 0)
                    ans = (ans + n - s) % n;
                else
                    ans = (ans + s) % n;
        }
    
        cout << name[ans] << endl;
        delete[] name;
        delete[] f;
    
        return 0;
    }
    
    
  • 0
    @ 2019-07-25 17:25:13

    分析:
    1.仔细看题目,找到有用信息;
    2.本题分量种情况:一个是小人面向内,另一个是向外;
    3.然后根据两种情况选择是向左还是向右;
    4.然后再分析一下加减的情况;
    不太会写题解,大家原谅。。。
    下面上代码O(n):
    #include<bits/stdc++.h>
    using namespace std;
    int n,m,w=1;
    struct node{
    int p,q;
    string z;
    }g[100010]; //定义结构体
    node h[100010];
    int main(){
    cin>>n>>m; //输入
    for(int i=1;i<=n;i++) cin>>g[i].p>>g[i].z; //循环输入
    for(int i=1;i<=m;i++) cin>>h[i].p>>h[i].q;
    for(int i=1;i<=m;i++){
    if(g[w].p==0){
    if(h[i].p==0) w-=h[i].q;
    else w+=h[i].q;
    } //小人面向内
    else{
    if(h[i].p==0) w+=h[i].q;
    else w-=h[i].q;
    } //小人面向外
    if(w<=0) w+=n; //进行加减
    if(w>n) w-=n;
    }
    cout<<g[w].z<<endl;
    return 0;
    }

  • 0
    @ 2018-09-01 08:51:09

    #include<iostream>
    #include<string>
    using namespace std;
    int ans=1,n,m;
    bool cx[100010],rl[100010];
    string s[100010];
    int gs[100010];
    int main()
    {
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    cin>>cx[i]>>s[i];
    }
    for(int i=1;i<=m;i++)
    {
    cin>>rl[i]>>gs[i];
    }
    for(int i=1;i<=m;i++)//cx 0表示朝向圈内,1表示朝向圈外//rl 0表示向左数,1表示向右数
    {
    if((cx[ans]==0&&rl[i]==1)||(cx[ans]==1&&rl[i]==0))
    {
    if(ans+gs[i]>n)
    {
    (ans+=gs[i])-=n;
    }
    else ans+=gs[i];
    }
    else
    {
    if(ans-gs[i]<=0)
    {
    (ans-=gs[i])+=n;
    }
    else ans-=gs[i];
    }
    }
    cout<<s[ans]<<endl;
    return 0;
    }

  • 0
    @ 2018-03-23 11:09:33
    #include <stdio.h>
    
    int face[100001];
    
    char name[100001][11];
    
    int main()
    {
        int n, m;
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%s", &face[i], name[i]);
            face[i] = face[i] * 2 - 1;
        }
        int pos = 1;
        for (int i = 0; i < m; i++)
        {
            int ai, si;
            scanf("%d%d", &ai, &si);
            ai = ai * 2 - 1;
            pos -= ai * face[pos] * si;
            if (pos < 1) pos += n;
            else if (pos > n) pos -= n;
        }
        printf("%s", name[pos]);
    }
    
  • 0
    @ 2017-11-05 23:05:19

    var m,n,i,j,k,l:longint;
    s:char;
    a,b,c:array[0..10100] of longint;
    st:array[0..10100] of string;
    begin

    readln(m,n);
    for i:=1 to m do
    readln(a[i],s,st[i]);
    for i:=1 to n do
    readln(b[i],c[i]);
    l:=1;
    k:=0;
    for i:=1 to n do
    begin
    if a[l]=0 then if b[i]=0 then l:=l-c[i]
    else l:=l+c[i]
    else if b[i]=0 then l:=l+c[i]
    else l:=l-c[i];
    if l>m then l:=l-m;
    if l<1 then l:=l+m;
    end;
    writeln(st[l]);

    end.

  • 0
    @ 2017-10-24 17:03:17
    /*
     *creat at 2017-10-13 18:31:24
     *author :XiongXuan
     */
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    #define inf 0x3f3f3f3f
    #define forn(i, n) for(int i = 0; i < n; i++)
    #define fornr(i, n) for(int i = n - 1; i >= 0; i--)
    
    /*
    思路:建立一个结构体数组d[MAXN],里面存朝向和姓名
    循环n次,输入所有人员的数据到d
    循环m次,每次输入一组a和s,用ans标记当前的人,减代表顺时针,加代表逆时针
    m次后,ans指向的是最后答案。
    要注意ans越界的问题。
     */
    
    struct DATA {
        int c;
        char name[14];
    }d[100005];
    
    int main () {
        // freopen("toy.in","r",stdin);
        // freopen("toy.out","w",stdout);
        
        int n, m, i, ans, a, s;
        cin >> n >> m;
    
        //循环n次,输入所有人员的数据到d
        for (i = 0; i < n; i++)
            scanf("%d %s", &d[i].c, d[i].name);
    
        ans = 0;
        //循环m次,每次输入一组a和s,用ans标记当前的人,
        for (i = 0; i < m; i++) {
            cin >> a >> s;
            //减代表顺时针,加代表逆时针
            if (a == 0) {
                if (d[ans].c == 0)
                    ans -= s;
                else
                    ans += s;
            }
            else {
                if (d[ans].c == 0)
                    ans += s;
                else
                    ans -= s;
            }
    
            //这里防止ans越界
            ans = (ans + n) % n;
        }
    
        //m次后,ans指向的是最后答案
        printf("%s\n", d[ans].name);
    
        return 0;
    }
    
  • 0
    @ 2017-10-15 11:38:05

    简洁

    #include<iostream>
    using namespace std;
    int main(){

    int n,m;
    cin>>n>>m;
    int a[m],s[m],count = 1;
    struct man{
    string name;
    int dir;
    }total[n+1];
    for(int i= 1;i<=n;i++){
    cin>>total[i].dir>>total[i].name;
    }
    for(int i = 0;i<m;i++){
    cin>>a[i]>>s[i];
    if(a[i] == total[count].dir){count = (count-s[i])%n; if(count<=0)count+=n;}
    else {count = (count+s[i])%n;if(count==0)count+=n;}
    }
    cout<<total[count].name;
    }

  • 0
    @ 2017-09-13 19:51:07

    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct p
    {
    string name;
    int turn;
    }a[100001];
    int main()
    {
    int n,m,x[100001],y[100001];
    int t=1;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i].turn>>a[i].name;
    for(int i=1;i<=m;i++)
    {
    cin>>x[i]>>y[i];
    if(a[t].turn!=x[i])
    {
    t+=y[i];
    while(t>n)t=t-n;
    }
    else
    {
    t-=y[i];
    while(t<=0)t=t+n;
    }
    }
    cout<<a[t].name;
    return 0;
    }

  • 0
    @ 2017-09-13 19:50:39

    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct p
    {
    string name;
    int turn;
    }a[100001];
    int main()
    {
    int n,m,x[100001],y[100001];
    int t=1;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i].turn>>a[i].name;
    for(int i=1;i<=m;i++)
    {
    cin>>x[i]>>y[i];
    if(a[t].turn!=x[i])
    {
    t+=y[i];
    while(t>n)t=t-n;
    }
    else
    {
    t-=y[i];
    while(t<=0)t=t+n;
    }
    }
    cout<<a[t].name;
    return 0;
    }

  • 0
    @ 2017-09-13 19:29:32

    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct p{
    string name;
    int turn;
    }a[21];
    int main()
    {
    int n,m,x[1001],y[1001];
    int t=1;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i].turn>>a[i].name;
    for(int i=1;i<=m;i++)
    {
    cin>>x[i]>>y[i];
    if(a[t].turn!=x[i])
    {
    t+=y[i];
    while(t>n)
    {
    t=t-n;
    }
    }
    else
    {
    t-=y[i];
    while(t<0)
    {
    t=t+n;
    }
    }
    }
    cout<<a[t].name;
    return 0;
    }

  • 0
    @ 2017-08-09 21:27:14

    148ms通过 写了ReadInt, ReadBoolReadStr 优化读入速度,并且做了循环展开qwq

    #include <cstdio>
    #include <cctype>
    
    const int MAXN = 100010;
    
    int n, m, x, pen;
    bool f, dir[MAXN];
    char name[MAXN][20];
    
    inline int ReadInt() {
      char _c; int sum(0);
      while (!isdigit(_c = getchar()));
      do sum = sum * 10 + _c - '0';
      while (isdigit(_c = getchar()));
      return sum;
    }
    
    inline bool ReadBool() {
      char _c;
      while (!isdigit(_c = getchar()));
      return (_c - '0') ? true : false;
    }
    
    inline void ReadStr(int th){
      register int num(0); char _c;
      while(isspace(_c = getchar()));
      do name[th][num++] = _c;
      while (isalpha(_c = getchar()));
    }
    
    int main() {
      n = ReadInt(), m = ReadInt();
      for (register int i = 0; i < n - 1; i += 2) {
        dir[i] = ReadBool();  ReadStr(i);
        dir[i + 1] = ReadBool(); ReadStr(i + 1);
      } if (n & 1) dir[n - 1] = ReadBool(), ReadStr(n - 1);
    
      for (register int i = 1; i <= m; ++i) {
        f = ReadBool(), x = ReadInt();
        if (f != dir[pen]) pen = (pen + x) % n;
        else pen = (pen + n - x) % n;
      } printf("%s\n", name[pen]);
      return 0;
    }
    
  • 0
    @ 2017-08-07 21:48:13

    //脑子清晰 数组别小就没问题
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <queue>
    using namespace std;
    int a[100001],b[100001],c[100001];
    char job[100001][11];
    int main()
    { int n,m,i,j,temp=1;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    cin>>a[i]>>job[i];
    for(i=1;i<=m;i++)
    cin>>b[i]>>c[i];
    for(i=1;i<=m;i++)
    {
    if(a[temp]==0)
    if(b[i]==0)
    {
    temp=temp-c[i];
    if(temp<=0)temp+=n;
    }
    else
    {
    temp=temp+c[i];
    if(temp>n)temp-=n;
    }
    else
    if(b[i]==0)
    {
    temp=temp+c[i];
    if(temp>n)temp-=n;
    }
    else
    {
    temp=temp-c[i];
    if(temp<=0)temp+=n;
    }
    }
    cout<<job[temp]<<endl;
    //system("pause");
    return 0;
    }

  • 0
    @ 2017-08-03 16:44:09

    简单模拟
    不弄乱了就可以 ^(* ̄(oo) ̄)^
    这是accepted的code:

    #include<bits/stdc++.h>
    using namespace std;
    int n,m,cnt,start;
    bool k[100001]; 
    string ppl[100001];
    void use(int con,int step)
    {
        int step0=step%n;
        if((con+k[start])%2==0)
        {
            start-=step0;
            if(start<=0)start+=n;
            return; 
        }
        else
        {
            start+=step0;
            if(start>n)start-=n;
            return;
        }
    }
    int main()
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            cin>>k[i]>>ppl[i];
        }
        bool con;
        int step;
        start=1;
        for(int i=1;i<=m;i++)
        {
            cin>>con>>step;
            use(con,step);
        }
        cout<<ppl[start];
    }
    

    之前写的过了18个(except NO.12 & NO.16)

    #include<bits/stdc++.h>
    using namespace std;
    int s[100005],_s,_a,n,m,p,now;
    char c[100005][15],ch;
    int main()
    {
        scanf("%d%d",&n,&m);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&s[i]);
            p=0;
            ch=getchar();
            while (ch!='\n')
            {
                ch=getchar();
                p++;
                c[i][p]=ch;
            }
            c[i][0]=p-1;
        }
        now=1;
        for (int i=1;i<=m;i++)
        {
            int fuck=now;
            scanf("%d%d",&_a,&_s);
            if (_a==0)
            {
                if (s[fuck]==0)
                    now=(now+n-(_s%n))%n;
                else if (s[fuck]==1)
                    now=(now+(_s%n))%n;
            }
            else if (_a==1)
            {
                if (s[fuck]==0)
                    now=(now+(_s%n))%n;
                else if (s[fuck]==1)
                    now=(now+n-(_s%n))%n;
            }
        }
        for (int i=1;i<=c[now][0];i++)
            printf("%c",c[now][i]);
        return 0;
    

    有人能帮我找一下错在哪儿吗?谢谢!

    • @ 2018-01-22 20:37:14

      12组数据应该是位置=0的情况,16组应该是跟now=...%n有关系,去掉,换成while(now<=0)now+=n;之类就好

  • 0
    @ 2017-07-06 23:40:06

    #include<iostream>
    #include<string>
    #include<vector>
    using namespace std;
    struct people
    {
    string job;
    bool facein;
    };
    vector<people> peos;
    int gl(int s, int n, int t) {

    if (n-s < 0)
    return t - (s - n);
    else
    return n - s;
    }
    int gn(int s, int n, int t) {

    if (s + n >= t)
    return s+n-t;
    else
    return n + s;
    }
    int main()
    {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
    people peo;
    cin >> peo.facein >> peo.job;
    if (peo.facein)
    peo.facein = false;
    else
    peo.facein = true;
    peos.push_back(peo);
    }
    int nowpeo = 0;
    for (int j = 0; j < m; j++) {
    int a, s;
    cin >> a >> s;
    bool t = peos[nowpeo].facein;
    if (a == 0 && t == true) {

    nowpeo = gl(s, nowpeo, n);
    }
    else if (a == 1 && t == false) {

    nowpeo = gl(s, nowpeo, n);
    }
    else {

    nowpeo = gn(s, nowpeo, n);
    }
    }
    cout << peos[nowpeo].job;
    }

  • 0
    @ 2017-06-08 15:44:19
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <queue>
    using namespace std;
    
    int n,m,p;
    vector<int> a;
    vector<string> na; 
    
    void c_v_1()
    {
        a.resize(0);
        na.resize(0);
    }
    
    int main()
    {
        while (~scanf("%d%d",&n,&m))
        {
            c_v_1();
            a.resize(n,0);
            na.resize(n);
            for (int i=0;i<n;i++)
            {
                na[i].resize(10,0);
                scanf("%d%s",&a[i],&(na[i][0]));
            }
            p=0;
            for (int i=1;i<=m;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                p+=((x^a[p]!=0)?y:-y);
                p=(p+n)%n;
            }
            printf("%s\n",na[p].c_str());
        }
    }
    
  • 0
    @ 2017-06-06 13:20:06
    #include<stdio.h>
    #include<iostream>
    #include<string>
    using namespace std;
    int n,m,s[100010],p=0;
    string w[100010];
    int main(){
        cin>>n>>m;
        for(int i=0;i<n;++i) cin>>s[i]>>w[i];
        for(int x,y;m--;){
            cin>>x>>y;
            p=(x^s[p])?p+y:p-y;
            p=(p+n)%n;
        }
        cout<<w[p];
    }
    
  • 0
    @ 2017-05-21 18:21:00

    exciting,在vijos发的第一个题解233,水一下就好。

    模拟就好了
    对于逆时针输入,把它当成顺时针的,后面的左右对调即可。
    移动时可能会产生负数或越界的,处理方式为 x=(n+x)与x%=n;
    x<0时,意味着当前位置在n向前数x绝对值个单位的位置,x>=n由于是个环形的,很显然是x%n。
    大概就是这样,稍微调试即可。

    环境:
    win10 64bit
    g++
    gdb
    atom(vim plugin)

    #include <iostream>
    #include <string>
    
    #define abs(x) ((x)>0?(x):(-(x)))
    #define log(x) std::cout << x << '\n';
    int n,m;
    struct Node{
      int dir;
      std::string name;
      Node(int dir=0,std::string name=""){}
    }node[100010];
    
    int main(int argc, char const *argv[]) {
      std::cin >> n >> m;
      for(int i=0;i<n;i++)std::cin >> node[i].dir >> node[i].name;
      int x=0;
      for(int i=0;i<m;i++){
        int dir,dis;std::cin >> dir >> dis;
        if(dir==node[x].dir)  x-=dis;
        else                  x+=dis;
        if(x<0) x=n+x;
        x%=n;
      }
      std::cout << node[x].name << '\n';
    
    
      return 0;
    }
    #if 0
    0 singer
    0 reader
    0 mengbier
    1 thinker
    1 archer
    0 writer
    1 mogician
    0 3
    1 1
    0 2
    
    #endif
    
    

信息

ID
2003
难度
6
分类
(无)
标签
递交数
2710
已通过
792
通过率
29%
被复制
10
上传者