超时,20分没了
查看原帖
超时,20分没了
241838
microchip楼主2020/7/20 08:19
#include<bits/stdc++.h>
using namespace std;

struct node{
	bool fx;
	string name;
};

int n,m;
node toy[100500];

/*7 3
0 singer
0 reader
0 mengbier 
1 thinker
1 archer
0 writer
1 mogician 
0 3
1 1
0 2*/

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>toy[i].fx>>toy[i].name;
	}
	int x=1,a,b;
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		if(a==0){
			if(toy[x].fx==0){
				for(int j=0;j<b;j++){
					x--;
					if(x==0){
						x=n;
					}
				}
			}else{
				for(int j=0;j<b;j++){
					x++;
					if(x>n){
						x-=n;
					}
				}
			}
		}else{
			if(toy[x].fx==0){
				for(int j=0;j<b;j++){
					x++;
					if(x>n){
						x-=n;
					}
				}
			}else{
				for(int j=0;j<b;j++){
					x--;
					if(x==0){
						x=n;
					}
				}
			}	
		}
	}
	cout<<toy[x].name<<endl;
	return 0;
}

有什么办法提高效率吗?还是我这个模拟写法本来就有问题?

2020/7/20 08:19
加载中...