@[xxc123](/user/787732) 你的方法本质就是错的。因为没加等待的时间。题目要求的是总时长而不是距离。
by xs_siqi @ 2023-04-04 23:11:22
@[xxc123](/user/787732) 这题实际上很难自然地离线下来做
by xs_siqi @ 2023-04-04 23:12:04
@[xs_siqi](/user/401088)
改后还是错的啊
```
#include<iostream>
using namespace std;
int main()
{
int east=0,south=0,west=0,north=0;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int T;
cin>>T;
while(T--)
{
char t;
cin>>t;
switch(t)
{
case 'E':east++;
case 'S':south++;
case 'W':west++;
case 'N':north++;
}
}
if(x1<=x2)
{
if(y1<=y2)
{
if(x2-x1<=east&&y2-y1<=south)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
else
{
if(x1-x2<=west&&y2-y1<=south)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
}
else
{
if(y1<=y2)
{
if(x1-x2<=east&&y2-y1<=north)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
else
{
if(x1-x2<=west&&y2-y1<=north)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
}
return 0;
}
by xxc123 @ 2023-04-05 18:54:06
我判断条件写错了
是要求步数
```
#include<iostream>
using namespace std;
int main()
{
int east=0,south=0,west=0,north=0;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
char t;
cin>>t;
switch(t)
{
case 'E':east++;break;
case 'S':south++;break;
case 'W':west++;break;
case 'N':north++;break;
}
}
if(x1<=x2)
{
if(y1<=y2)
{
if(x2-x1<=north&&y2-y1<=east)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
}
else
{
if(x2-x1<=north&&y1-y2<=west)
{
cout<<x2-x1+y1-y2<<endl;
return 0;
}
}
}
else
{
if(y1<=y2)
{
if(x1-x2<=south&&y2-y1<=east)
{
cout<<x1-x2+y2-y1<<endl;
return 0;
}
}
else
{
if(x1-x2<=south&&y1-y2<=west)
{
cout<<x1-x2+y1-y2<<endl;
return 0;
}
}
}
cout<<-1<<endl;
return 0;
}
by xxc123 @ 2023-04-05 19:26:47
@[xs_siqi](/user/401088)
现在对了
by xxc123 @ 2023-04-05 19:27:27