9,10,11,13TLE 求助,C++
查看原帖
9,10,11,13TLE 求助,C++
916797
ffff0505k楼主2023/1/25 09:51

rt C++98 代码中有部分有一定技巧,即如果面对的方向与左右的值相同就顺时针转,否则就逆时针转

#include <iostream>
using namespace std;

struct list
{
    int status;//status和输入相同的话,就是顺时针
    char job[11];
    struct list * prev;
    struct list * next;
};
list *head;

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;
}
2023/1/25 09:51
加载中...