评测机炸了……(求助)
查看原帖
评测机炸了……(求助)
335094
Lucifero楼主2020/7/10 09:56
#include <bits/stdc++.h>
using namespace std;
bool visited[20][200000];
class Line
{
public:
	int X,time;
}_next[20],_now[20];
class sum
{
public:
	queue<Line> cowfar;
}haha[20];
int main()
{
	//[USACO]Catch That Cow S
	int t,N,K,i;
	scanf("%d",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%d%d",&N,&K);
		_now[i].X=N;_now[i].time=0;
		haha[i].cowfar.push(_now[i]);
		if (K<=N)
		{
			printf("%d",N-K);
			return 0;
		}
		while(!haha[i].cowfar.empty())
		{
			_now[i]=haha[i].cowfar.front();
			haha[i].cowfar.pop();
			if (_now[i].X+1==K || _now[i].X-1==K || _now[i].X*2==K) break;
			if (_now[i].X+1<K && !visited[i][_now[i].X+1])
			{
				_next[i].X=_now[i].X+1;
				_next[i].time=_now[i].time+1;
				haha[i].cowfar.push(_next[i]);
				visited[i][_next[i].X]=true;
			}
			if (_now[i].X-1>=0 && !visited[i][_now[i].X-1])
			{
				_next[i].X=_now[i].X-1;
				_next[i].time=_now[i].time+1;
				haha[i].cowfar.push(_next[i]);
				visited[i][_next[i].X]=true;
			}
			if (_now[i].X*2<=K*2 && !visited[i][_now[i].X*2])
			{
				_next[i].X=_now[i].X*2;
				_next[i].time=_now[i].time+1;
				haha[i].cowfar.push(_next[i]);
				visited[i][_next[i].X]=true;
			}
		}
		printf("%d",_now[i].time+1);
	}
}

评测记录

2020/7/10 09:56
加载中...