冰雪大冒险
时间限制:1秒 占用内存:128M
题目:
![](https://img-blog.csdnimg.cn/img_convert/24d3f9e5c9aaf42738dc11b81633c01d.png)
格式:
![](https://img-blog.csdnimg.cn/img_convert/682c3287dc2cdf9f2e7df412d472c1eb.jpeg)
样例1:
输入:
5 5
2 2
6
1 3
1 5
3 4
4 2
5 3
5 5
DRDRULUR
输出:1 2
样例1解释:
![](https://img-blog.csdnimg.cn/img_convert/fabb6ddc7c845358ac216c8cb7f97d34.jpeg)
代码:
#include<bits/stdc++.h>
#include <iostream>
#include<string>
using namespace std;
int n,m;
int x,y,k;
struct Node{
int a;
int b;
}Node[1000];
bool isYes(int x,int y){
if(x<1||x>n||y<1||y>m) return false;
for(int i=1;i<=k;i++){
if(x==Node[i].a&&y==Node[i].b) return false;
}
return true;
}
int main( )
{
cin>>n>>m;
cin>>x>>y;
cin>>k;
for(int i=1;i<=k;i++){
int a,b;
cin>>a>>b;
Node[i].a=a;
Node[i].b=b;
}
string str;
cin>>str;
int xnow=x;
int ynow=y;
for(int j=0;j<str.length();j++){
if(str[j]=='L') {while(isYes(xnow,ynow))ynow--; ynow++;}
if(str[j]=='R') {while(isYes(xnow,ynow))ynow++; ynow--;}
if(str[j]=='U') {while(isYes(xnow,ynow))xnow--; xnow++;}
if(str[j]=='D') {while(isYes(xnow,ynow))xnow++; xnow--;}
}
cout<<xnow<<ynow;
return 0;
}