永发信息网

ACM poj 1835宇航员题,我写的代码已经运行啦,但一提交就是WA,高手们帮我看看吧

答案:2  悬赏:40  手机版
解决时间 2021-12-28 11:46
void go(int &x,int &y,int &z,int &f,int &r,int &u,int d,int move)
{
int t;
switch(d)
{
case 0:break; //前
case 1:f=-f;r=-r;break; //后
case 2:t=f;f=-r;r=t;break; //向左
case 3:t=f;f=r;r=-t;break; //向右
case 4:t=f;f=u;u=-t;break; //向上
case 5: t=f;f=-u;u=-t;break; //向下
}
switch(f)
{
case 7:x+=move;break;
case 8:y+=move;break;
case 9:z+=move;break;
case -7:x-=move;break;
case -8:y-=move;break;
case -9:z-=move;break;
}
}
最佳答案
#include

typedef struct
{
int x,y,z;
}dir;

void forward(dir* loc, dir* face, dir* top, int x)
{
loc->x += face->x * x;
loc->y += face->y * x;
loc->z += face->z * x;
}

void back(dir* loc, dir* face, dir* top, int x)
{
face->x *= -1;
face->y *= -1;
face->z *= -1;
forward(loc,face,top,x);
}

void right(dir* loc, dir* face, dir* top, int x)
{
dir temp;
temp.x = top->y * face->z - face->y * top->z;
temp.y = top->z * face->x - face->z * top->x;
temp.z = top->x * face->y - face->x * top->y;
*face = temp;
forward(loc,face,top,x);
}

void left(dir* loc, dir* face, dir* top, int x)
{
dir temp;
temp.x = face->y * top->z - top->y * face->z;
temp.y = face->z * top->x - top->z * face->x;
temp.z = face->x * top->y - top->x * face->y;
*face = temp;
forward(loc,face,top,x);
}

void up(dir* loc, dir* face, dir* top, int x)
{
dir temp = *top;
*top = *face;
top->x *= -1;
top->y *= -1;
top->z *= -1;
*face = temp;
forward(loc,face,top,x);
}

void down(dir* loc, dir* face, dir* top, int x)
{
dir temp = *face;
*face = *top;
face->x *= -1;
face->y *= -1;
face->z *= -1;
*top = temp;
forward(loc,face,top,x);
}

int main()
{
int m,n,x;
dir loc,top,face;
char cmd[8];
scanf("%d",&m);
while(m--)
{
loc.x = loc.y = loc.z = 0;
top.x = top.y = 0;
top.z = 1;
face.z = face.y = 0;
face.x = 1;
scanf("%d",&n);
while(n--)
{
scanf("%s%d",cmd,&x);
switch(cmd[0])
{
case 'l':
left(&loc,&face,&top,x);
break;
case 'r':
right(&loc,&face,&top,x);
break;
case 'u':
up(&loc,&face,&top,x);
break;
case 'd':
down(&loc,&face,&top,x);
break;
case 'b':
back(&loc,&face,&top,x);
break;
case 'f':
forward(&loc,&face,&top,x);
break;
}
}
printf("%d %d %d ",loc.x,loc.y,loc.z);
if(face.x == 1)
{
puts("0");
}
else if(face.y == 1)
{
puts("1");
}
else if(face.z == 1)
{
puts("2");
}
else if(face.x == -1)
{
puts("3");
}
else if(face.y == -1)
{
puts("4");
}
else if(face.z == -1)
{
puts("5");
}

}
}
全部回答
搜一下:ACM poj 1835宇航员题,我写的代码已经运行啦,但一提交就是WA,高手们帮我看看吧
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
error C2065: 'Messsagebox' : und
单选题下列物质中,属于纯净物的是()A.天然
分解因式:m2(x-2y)-2m(2y-x)+(x-2y)__
公仔碗仔面 海鲜 猪骨 哪个好吃
对下图所能表示的生物学意义(不考虑面积的大
2倍根号6除以(根号2+根号3+根号5)的值为多
单选题用细线拴住一个小球在光滑的水平面内做
OPT有副作用么,私立美容院做的怎么样?
单选题2007年12月18日,国资委主任李荣融在中
读图回答: (1)写出下列各点
如何在Windows XP SP3上安装.NET FRAMEWORK 3
The sad movie makes me .A. cry B. to cryC.
请问新捷达1.4手动时尚版和1.4手动舒适版有什
三星SM-N9002是note3吗?怎么区分联通版还是
书包网怎么上不了?
推荐资讯
与同事关系弄僵了,产生蝴蝶效应,很多同事都
求QQ音乐歌单。我要的是歌曲连起来能凑成一些
填空题已知三个平面α,β,γ,若β⊥γ,且
启明星辰这样的走势,我是继续持有.还是出手
如图,用三角尺可按下面方法画角平分线:在已
宝宝满月了大便还是绿色的正常吗
如何在自招的自荐信中表现创新潜质
三门县供电局供电营业厅地址在哪?我要去那里
怎么根据年轮辨别方向?
涧西区洛阳重庆路一社区文化活动中心地址在哪
急求《我看屈原》一文,(100--200字)
降生于山东曹县五里墩的克隆牛,从体细胞的培
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?