P1518 [USACO2.4]两只塔姆沃斯牛 小疑问
  • 板块灌水区
  • 楼主Vrandy
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/5/10 21:23
  • 上次更新2023/10/28 01:44:03
查看原帖
P1518 [USACO2.4]两只塔姆沃斯牛 小疑问
635303
Vrandy楼主2022/5/10 21:23

模仿题解,成功解决了问题,但是感觉题解的移动函数中x是纵向的,y是横向的,我修改后不能通过了,为啥捏

题解:

void move(int x,int y,int mi,int h){//x,y为x,y坐标,mi为方向,h为类型:农夫为0,奶牛为1
	if (mi==0){
		if (m[x-1][y]=='*') if (h==0) f[0]=1; else c[0]=1;
		else if (h==0) f[1]--; else c[1]--;
	}else if (mi==1){
		if (m[x][y+1]=='*') if (h==0) f[0]=2; else c[0]=2;
		else if (h==0) f[2]++; else c[2]++;
	}else if (mi==2){
		if (m[x+1][y]=='*') if (h==0) f[0]=3; else c[0]=3;
		else if (h==0) f[1]++; else c[1]++;
	}else{
		if (m[x][y-1]=='*') if (h==0) f[0]=0; else c[0]=0;
		else if (h==0) f[2]--; else c[2]--;
	}
}

我的:

void move(int x, int y, int mi, int h)
{
	if (mi == 0) //向北
	{
		if (map[x][y-1] == '*') if (h == 0) john[0] = 1; else cow[0] = 1;//改变方向
		else if (h == 0) john[2]--; else cow[2]--;
	}
	else if (mi == 1)//向东
	{
		if (map[x+1][y ] == '*') if (h == 0) john[0] = 2; else cow[0] = 2;
		else if (h == 0) john[1]++; else cow[1]++;
	}
	else if (mi == 2)//向南
	{
		if (map[x][y+1] == '*') if (h == 0) john[0] = 3; else cow[0] = 3;
		else if (h == 0) john[2]++; else cow[2]++;
	}
	else //向西
	{
		if (map[x-1][y ] == '*') if (h == 0) john[0] = 0; else cow[0] = 0;
		else if (h == 0) john[1]--; else cow[1]--;
	}
}
2022/5/10 21:23
加载中...