题解

34 条题解

  • 0
    @ 2017-05-04 13:37:08
    #include<bits/stdc++.h>
    using namespace std;
    int n,m,c,l=0;
    bool f;
    struct node{
        bool b;
        string name;
    }line[500007];
    int main(){
        cin>>n>>m;
        for(int i=0;i<n;i++) cin>>line[i].b>>line[i].name;
        for(int i=1;i<=m;i++){
            cin>>f>>c;
            if(line[l].b==1) if(f==0)l+=c;else l-=c;
            else if(f==0)l-=c;else l+=c;
            if(l>=n) l-=n;
            if(l<0) l+=n;
        }
        cout<<line[l].name;
    }
    
  • 0
    @ 2017-02-17 11:21:12

    为什么测试点是随机的,害的我掉了百分之一的AC率555……
    题解送上

    #include<bits/stdc++.h>
    using namespace std;
    bool a[100001];
    char x[200001][1001];
    int b,y;
    int main()
    {
        int i,j,k=0,l,n,m;
        cin>>n>>m;
        for(i=0;i<n;i++) cin>>a[i]>>x[i];
        for(i=0;i<m;i++) {
            cin>>b>>y;
            if(a[k]) b=(b+1)%2;
            if(b) k+=y;
            else k-=y;
            if(k<0) k+=n;
            if(k>n-1) k-=n;
        }
        cout<<x[k]<<endl;
        return 0;
    }
    
    
  • 0
    @ 2017-02-17 11:02:17
    
    #include<bits/stdc++.h>
    using namespace std;
    struct alk{
        bool d;
        string h;
    };
    alk a[100000];
    int m,n,e=0;
    int main()
    {
        cin>>n>>m;
        for(int i=0;i<n;i++){
            cin>>a[i].d>>a[i].h;
        }
        while(m--){
            bool x;
            int y;
            cin>>x>>y;
            bool r=x^a[e].d;
            e= r ? e+y:e-y;
            if(e<0)e+=n;
            if(e>n-1)e-=n;
        }
        cout<<a[e].h<<endl;
        return 0;
    }
    
    
  • 0
    @ 2017-02-17 11:01:24
    #include<bits/stdc++.h> 
    
    using namespace std;
    struct alk{
     bool d;
     string h;
    };
    alk a[100000];
    int m,n,e=0;
    int main()
    {
     cin>>n>>m;
     for(int i=0;i<n;i++){ cin>>a[i].d>>a[i].h;
     }
     while(m--){
     bool x;
     int y;
     cin>>x>>y;
     bool r=x^a[e].d;
     e= r ? e+y:e-y;
     if(e<0)e+=n; if(e>n-1)e-=n;
     }
     cout<<a[e].h<<endl;
     return 0;
    }
    
    
    
  • 0
    @ 2017-02-15 20:00:36

    var
    zy:array[1..100000]of string;
    a:array[1..100000]of integer;
    i,n,m,bj,x,y:longint;
    begin
    bj:=1;
    read(n,m);
    for i:=1 to n do
    begin
    read(a[i],zy[i]);
    end;
    for i:=1 to m do
    begin
    read(x,y);
    if (x=0)and(a[bj]=0)then bj:=bj-y else
    if (x=0)and(a[bj]=1)then bj:=bj+y else
    if (x=1)and(a[bj]=0)then bj:=bj+y else
    if (x=1)and(a[bj]=1)then bj:=bj-y;
    if bj>n then bj:=bj-n;
    if bj<1 then bj:=bj+n;
    end;
    writeln(zy[bj]);
    end.

  • -1
    @ 2018-05-26 14:53:12
    #include<bits/stdc++.h> 
    using namespace std;
    const int maxn=1e5;
    char name[maxn][11];
    int arr[maxn];
    int n,m;
    int t=0;
    int word1[maxn],word2[maxn];
    int main()
    {
        ios::sync_with_stdio(false);
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i]>>name[i];
        }
        for(int i=0;i<m;i++)
        {
            cin>>word1[i]>>word2[i];
        }
        for(int i=0;i<m;i++)
        {
            if(arr[t]==0&&word1[i]==0||arr[t]==1&&word1[i]==1) 
            {
                t-=word2[i];
                if(t<0) t=n+t;
                
            }
            else if(arr[t]==0&&word1[i]==1||arr[t]==1&&word1[i]==0)
            {
                t+=word2[i];
                if(t>n-1) t=t-n;
            }   
        }
        cout<<name[t];
    }
    
  • -1
    @ 2018-01-22 20:35:41

    数组开100000的时候Dev似乎编译出来挂掉,但Vijos就运行得很OK
    12组数据应该是位置=0的情况,16组应该是跟%n有关

    #include <cmath>
    #include <cstring>
    #include <iostream>
    using namespace std;
    int main(){
        int pos=1;
        int n,m,i=0;
        int dir[100000];
        int cmd[2][100000];
        char name[100000][11];
        memset(dir,0,sizeof(dir));
        memset(cmd,0,sizeof(cmd));
        memset(name,0,sizeof(name)); 
        scanf("%d%d",&n,&m);
        for(i=1;i<=n;i++)
            scanf("%d%s",&dir[i],&name[i]);
        for(i=1;i<=m;i++){
            scanf("%d%d",&cmd[0][i],&cmd[1][i]);
            if(cmd[0][i]==dir[pos]){
                pos-=cmd[1][i];
                while(pos<=0)pos+=n;
            } 
            else{ 
                pos+=cmd[1][i];
                while(pos>n)pos-=n;
            }
        }
        printf("%s",name[pos]);
        return 0;
    }
    
  • -1
    @ 2017-11-04 23:01:43

    //20 line 超短!!!
    #include <iostream>
    #include <string>
    using namespace std;
    string name[100005];
    int chao[100005],n,m,a,s,now=1;
    int main()
    {
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>chao[i]>>name[i];
    for(int i=1;i<=m;i++)
    {
    cin>>a>>s;
    if(chao[now]==a)
    now-=now-s>0?s:s-n;
    else
    now+=now+s>n?s-n:s;
    }
    cout<<name[now]<<endl;

    }

  • -1
    @ 2017-11-03 16:57:40

    暴力(注意数组大小)
    #include<bits/stdc++.h>
    using namespace std;
    int n,m,a[1000008],b,c;
    string s[1000008];
    int main()
    {
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i]>>s[i];
    int k=0;
    for(int i=1;i<=m;i++)
    {
    cin>>b>>c;
    if((b&&a[k])||(!b&&!a[k]))
    k=(k+n-c)%n;
    else
    k=(k+c)%n;
    }
    cout<<s[k];
    return 0;
    }

  • -1
    @ 2017-10-23 16:48:48

    #include<bits/stdc++.h>
    using namespace std;
    int c[200001],d[200001];
    struct zym
    {
    int x;
    char b[21];
    }
    a[200001];
    int main()
    {
    int n,m,s=1;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
    scanf("%d %s",&a[i].x,a[i].b);
    }
    for(int i=1;i<=m;i++)
    {
    scanf("%d%d",&d[i],&c[i]);
    }
    for(int i=1;i<=m;i++)
    {
    if(d[i]!=a[s].x)
    {
    s+=c[i];
    if(s>n)
    {
    s-=n;
    }
    }
    else
    {
    s-=c[i];
    if(s<1)
    {
    s+=n;
    }
    }
    }
    printf("%s",a[s].b);
    return 0;
    }

  • -1
    @ 2017-10-20 23:56:53

    第12个数据怎么过?

  • -1
    @ 2017-10-19 21:59:54

    一道简单的模拟
    对n取余即可
    注意%n==0的情况
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    using namespace std;
    string s[100011];
    int n,m,a[100011];
    int main()
    {
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {scanf("%d",&a[i]);
    cin>>s[i];
    }
    int t=0;int x,y;
    for(int i=1;i<=m;i++)
    {
    scanf("%d%d",&x,&y);
    if(x==1)
    {
    if(a[t]==0)t=(t+y)%n;
    else t=(t-y+n)%n;
    }
    if(x==0)
    {
    if(a[t]==0)t=(t-y+n)%n;
    else t=(t+y)%n;
    }
    }
    cout<<s[t];
    return 0;
    }

  • -1
    @ 2017-02-18 17:09:34

    什么情况!!!
    为什么我的数组下标从1到n就挂了,0到n-1就a了!!我靠,什么鬼
    附上原来的代码:
    c++
    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    bool a[100005];
    string name[100005];
    struct he{
    bool a;
    int b;
    }b[100005];
    int main()
    {
    memset(a,0,sizeof(a));
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i]>>name[i];
    for(int i=1;i<=m;i++) cin>>b[i].a>>b[i].b;
    int ans=1;
    for(int i=1;i<=m;i++){
    if((a[ans]+b[i].a)%2==0) ans-=b[i].b;
    else ans+=b[i].b;
    while(ans<=0) ans+=n;
    while(ans>n) ans-=n;
    }
    cout<<name[ans]<<endl;
    return 0;
    }

    现在的正解:
    c++
    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    bool a[100005];
    string name[100005];
    struct he{
    bool a;
    int b;
    }b[100005];
    int main()
    {
    memset(a,0,sizeof(a));
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>a[i]>>name[i];
    for(int i=0;i<m;i++) cin>>b[i].a>>b[i].b;
    int ans=0;
    for(int i=0;i<m;i++){
    if((a[ans]+b[i].a)%2==0) ans-=b[i].b;
    else ans+=b[i].b;
    while(ans<0) ans+=n;
    while(ans>n) ans-=n;
    }
    cout<<name[ans]<<endl;
    return 0;
    }

  • -1
    @ 2017-02-17 11:00:57

    #include<bits/stdc++.h>
    using namespace std;
    struct alk{
    bool d;
    string h;
    };
    alk a[100000];
    int m,n,e=0;
    int main()
    {
    cin>>n>>m;
    for(int i=0;i<n;i++){
    cin>>a[i].d>>a[i].h;
    }
    while(m--){
    bool x;
    int y;
    cin>>x>>y;
    bool r=x^a[e].d;
    e= r ? e+y:e-y;
    if(e<0)e+=n;
    if(e>n-1)e-=n;
    }
    cout<<a[e].h<<endl;
    return 0;
    }

信息

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