9,10,11,13TLE 求助,C++

P1563 [NOIP2016 提高组] 玩具谜题

@[ffff0505k](/user/916797) 我用你的代码试了一遍,9,10,11,13TLE,其余全都是WA
by 2013zhoujy @ 2023-01-25 10:58:12


@[zhoujiayou](/user/929408) ```cpp #include <iostream> using namespace std; struct list { int status;//status和输入相同的话,就是顺时针 char job[11]; struct list * prev; struct list * next; }; list *head; list * Create(int n) { list *pointer=NULL; list *q=NULL; head=NULL; return NULL; } int main() { int m=0,n=0; cin>>n>>m;//n为人的个数 list *temp=head; list *p=NULL; list *q=NULL; for(int i=0;i<n;i++)//默认从1-n是逆时针排序,顺时针就访问prev { /*temp=new list; cin>>temp->status>>temp->job; //cout<<temp->status<<" "<<temp->job<<endl; temp=temp->next;*/ p=new list; cin>>p->status>>p->job; if(head==NULL) head=p; else q->next=p; q=p; } //cout<<head->next->next->job<<endl; temp=head; for(int i=0;i<n;i++) { if(i<(n-1)) { list *t=temp->next; t->prev=temp; } if(i==(n-1)) { temp->next=head; head->prev=temp; } temp=temp->next; } list *pointer=head; for(int i=0;i<m;i++) { int direc=0; int step=0; cin>>direc>>step; if(pointer->status==direc) { for(int j=0;j<step;j++) pointer=pointer->prev; continue; } if(pointer->status!=direc) { for(int j=0;j<step;j++) pointer=pointer->next; continue; } } cout<<pointer->job<<endl; return 0; } ``` C++98
by ffff0505k @ 2023-01-25 13:12:33


@[zhoujiayou](/user/929408) 我其他都是AC。。。
by ffff0505k @ 2023-01-25 13:13:01


|