您的位置:首页 > 其它

2012 金华现场赛K题

2012-10-30 14:52 302 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4452

英语弱成渣,没看懂题目之前,样例没看明白。。trun around没注意。还有交换方向的时候理解错一句话,应该是题目写错了。

模拟就是

View Code

#include <stdio.h>
#include <stdlib.h>

int main()
{
int n,t1,s1,t2,s2,k;
char ch1,ch2;
char temp1,temp2;
int x1,y1,x2,y2;
int i;
int count1,count2;
while(~scanf("%d",&n),n)
{
x1=y1=1;
x2=y2=n;
count1=0;
count2=0;
getchar();
scanf("%c%d%d",&ch1,&s1,&t1);
getchar();
scanf("%c%d%d",&ch2,&s2,&t2);
scanf("%d",&k);
temp1=ch1;
temp2=ch2;
for(i=1;i<=k;i++)
{
count1++;
count2++;

if(ch1=='E')
{
x1+=s1;

if(x1>n)
{
ch1='W';
x1=2*n-x1;
}

}
else if(ch1=='W')
{

x1-=s1;
if(x1<1)
{
ch1='E';
x1=2*1-x1;
}
}

else if(ch1=='N')
{

y1-=s1;
if(y1<1)
{
ch1='S';
y1=2*1-y1;
}
}
else if(ch1=='S')
{
y1+=s1;

if(y1>n)
{

ch1='N';
y1=2*n-y1;
}
}

if(ch2=='E')
{
x2+=s2;

if(x2>n)
{
ch2='W';
x2=2*n-x2;
}

}
else if(ch2=='W')
{

x2-=s2;
if(x2<1)
{
ch2='E';
x2=2*1-x2;
}
}

else if(ch2=='N')
{

y2-=s2;
if(y2<1)
{
ch2='S';
y2=2*1-y2;
}
}
else if(ch2=='S')
{
y2+=s2;

if(y2>n)
{

ch2='N';
y2=2*n-y2;
}
}

//printf("%c   %c\n%d %d\n\n\n",ch2,ch1,y2,x2);
if(x1==x2&&y1==y2)
{
char tp;
tp=ch1;
ch1=ch2;
ch2=tp;
}
else
{
if(count1>=t1)
{

if(ch1=='E') ch1='N';
else if(ch1=='N') ch1='W';
else if(ch1=='S') ch1='E';
else if(ch1=='W') ch1='S';
count1=0;
}
if(count2>=t2)
{
if(ch2=='E') ch2='N';
else if(ch2=='N') ch2='W';
else if(ch2=='S') ch2='E';
else if(ch2=='W') ch2='S';
count2=0;

}
}

//printf("[[%d %d]],[[%d %d]][[%c]]\n",y1,x1,y2,x2,ch2);

}
printf("%d %d\n%d %d\n",y1,x1,y2,x2);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: